Search in sources :

Example 31 with LocalTime

use of org.joda.time.LocalTime in project killbill by killbill.

the class TestContiguousIntervalConsumableInArrear method testGetRolledUpUsageUsageAtTransitionTimes.

@Test(groups = "fast")
public void testGetRolledUpUsageUsageAtTransitionTimes() throws Exception {
    final DefaultTieredBlock tieredBlock1 = createDefaultTieredBlock("unit", 100, 1000, BigDecimal.ONE);
    final DefaultTier tier = createDefaultTierWithBlocks(tieredBlock1);
    final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, TierBlockPolicy.ALL_TIERS, tier);
    // 2015-03-15T18:10:17Z
    final LocalDate t0 = new LocalDate(2015, 03, BCD);
    final BillingEvent eventT0 = createMockBillingEvent(t0.toDateTime(new LocalTime(18, 10, 17), DateTimeZone.UTC), BillingPeriod.MONTHLY, Collections.<Usage>emptyList(), catalogEffectiveDate);
    Mockito.when(eventT0.getTransitionType()).thenReturn(SubscriptionBaseTransitionType.CREATE);
    // 2015-04-01T11:22:30Z
    final LocalDate t1 = new LocalDate(2015, 04, 01);
    final BillingEvent eventT1 = createMockBillingEvent(t1.toDateTime(new LocalTime(11, 22, 30), DateTimeZone.UTC), BillingPeriod.MONTHLY, Collections.<Usage>emptyList(), catalogEffectiveDate);
    Mockito.when(eventT1.getTransitionType()).thenReturn(SubscriptionBaseTransitionType.CANCEL);
    final LocalDate targetDate = t1;
    // At t0
    final RawUsageRecord raw1 = new DefaultRawUsage(subscriptionId, t0, "unit", 12L, "tracking-1");
    // At t1
    final RawUsageRecord raw2 = new DefaultRawUsage(subscriptionId, t1, "unit", 10L, "tracking-2");
    // Should be ignored
    final RawUsageRecord raw3 = new DefaultRawUsage(subscriptionId, new LocalDate(2015, 04, 02), "unit", 100L, "tracking-3");
    final List<RawUsageRecord> rawUsageRecord = ImmutableList.of(raw1, raw2, raw3);
    final ContiguousIntervalUsageInArrear intervalConsumableInArrear = createContiguousIntervalConsumableInArrear(usage, rawUsageRecord, targetDate, true, eventT0, eventT1);
    final List<RolledUpUsageWithMetadata> rolledUpUsage = intervalConsumableInArrear.getRolledUpUsage().getUsage();
    assertEquals(rolledUpUsage.size(), 1);
    assertEquals(rolledUpUsage.get(0).getSubscriptionId(), subscriptionId);
    assertEquals(rolledUpUsage.get(0).getStart().compareTo(t0), 0);
    assertEquals(rolledUpUsage.get(0).getEnd().compareTo(t1), 0);
    assertEquals(rolledUpUsage.get(0).getRolledUpUnits().size(), 1);
    assertEquals(rolledUpUsage.get(0).getRolledUpUnits().get(0).getUnitType(), "unit");
    assertEquals(rolledUpUsage.get(0).getRolledUpUnits().get(0).getAmount().longValue(), 22L);
}
Also used : RawUsageRecord(org.killbill.billing.usage.api.RawUsageRecord) LocalTime(org.joda.time.LocalTime) DefaultUsage(org.killbill.billing.catalog.DefaultUsage) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultRawUsage(org.killbill.billing.usage.api.svcs.DefaultRawUsage) DefaultTieredBlock(org.killbill.billing.catalog.DefaultTieredBlock) DefaultTier(org.killbill.billing.catalog.DefaultTier) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 32 with LocalTime

use of org.joda.time.LocalTime in project qi4j-sdk by Qi4j.

the class DateTextFieldWithPicker method earliestDate.

public DateTextFieldWithPicker earliestDate(LocalDate newEarliestDate) {
    if (selectedDate != null && newEarliestDate.isAfter(selectedDate)) {
        throw new IllegalArgumentException("Earliest date can't be before selected day.");
    }
    earliestDate = newEarliestDate;
    // Input field validation - date should be _after_ minimumDate (not the same)
    LocalDate minimumDate = newEarliestDate.minusDays(1);
    Date convertedMinimumDate = new DateTime(minimumDate.toDateTime(new LocalTime())).toDate();
    add(DateValidator.minimum(convertedMinimumDate));
    return this;
}
Also used : LocalTime(org.joda.time.LocalTime) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Example 33 with LocalTime

use of org.joda.time.LocalTime in project beam by apache.

the class CivilTimeEncoder method decodePacked64TimeMicros.

/**
 * Decodes {@code bitFieldTimeMicros} as a {@link LocalTime} with microseconds precision.
 *
 * <p>Encoding is as the following:
 *
 * <pre>
 *        6         5         4         3         2         1
 * MSB 3210987654321098765432109876543210987654321098765432109876543210 LSB
 *                                | H ||  M ||  S ||-------micros-----|
 * </pre>
 *
 * <p><b>Warning: LocalTime only supports milliseconds precision. Result is truncated.</b>
 *
 * @see #encodePacked64TimeMicros(LocalTime)
 * @see #decodePacked64TimeMicrosAsJavaTime(long)
 */
// should return a java.time.LocalTime
@SuppressWarnings("GoodTime")
public static LocalTime decodePacked64TimeMicros(long bitFieldTimeMicros) {
    checkValidBitField(bitFieldTimeMicros, TIME_MICROS_MASK);
    int bitFieldTimeSeconds = (int) (bitFieldTimeMicros >> MICRO_LENGTH);
    LocalTime timeSeconds = decodePacked32TimeSeconds(bitFieldTimeSeconds);
    int microOfSecond = getFieldFromBitField(bitFieldTimeMicros, MICRO_MASK, MICRO_SHIFT);
    checkValidMicroOfSecond(microOfSecond);
    LocalTime time = timeSeconds.withMillisOfSecond(microOfSecond / 1_000);
    checkValidTimeMillis(time);
    return time;
}
Also used : LocalTime(org.joda.time.LocalTime)

Example 34 with LocalTime

use of org.joda.time.LocalTime in project beam by apache.

the class CivilTimeEncoder method decodePacked64TimeNanos.

/**
 * Decodes {@code bitFieldTimeNanos} as a {@link LocalTime} with nanoseconds precision.
 *
 * <p>Encoding is as the following:
 *
 * <pre>
 *        6         5         4         3         2         1
 * MSB 3210987654321098765432109876543210987654321098765432109876543210 LSB
 *                      | H ||  M ||  S ||---------- nanos -----------|
 * </pre>
 *
 * <p><b>Warning: LocalTime only supports milliseconds precision. Result is truncated.</b>
 *
 * @see #encodePacked64TimeNanos(LocalTime)
 * @see #decodePacked64TimeNanosAsJavaTime(long)
 */
// should return a java.time.LocalTime
@SuppressWarnings("GoodTime")
public static LocalTime decodePacked64TimeNanos(long bitFieldTimeNanos) {
    checkValidBitField(bitFieldTimeNanos, TIME_NANOS_MASK);
    int bitFieldTimeSeconds = (int) (bitFieldTimeNanos >> NANO_LENGTH);
    LocalTime timeSeconds = decodePacked32TimeSeconds(bitFieldTimeSeconds);
    int nanoOfSecond = getFieldFromBitField(bitFieldTimeNanos, NANO_MASK, NANO_SHIFT);
    checkValidNanoOfSecond(nanoOfSecond);
    LocalTime time = timeSeconds.withMillisOfSecond(nanoOfSecond / 1_000_000);
    checkValidTimeMillis(time);
    return time;
}
Also used : LocalTime(org.joda.time.LocalTime)

Example 35 with LocalTime

use of org.joda.time.LocalTime in project beam by apache.

the class CivilTimeEncoder method decodePacked64DatetimeSeconds.

/**
 * Decodes {@code bitFieldDatetimeSeconds} as a {@link LocalDateTime} with seconds precision.
 *
 * <p>Encoding is as the following:
 *
 * <pre>
 *        6         5         4         3         2         1
 * MSB 3210987654321098765432109876543210987654321098765432109876543210 LSB
 *                             |--- year ---||m || D || H ||  M ||  S |
 * </pre>
 *
 * @see #encodePacked64DatetimeSeconds(LocalDateTime)
 * @see #decodePacked64DatetimeSecondsAsJavaTime(long)
 */
// should return a java.time.LocalDateTime
@SuppressWarnings("GoodTime")
public static LocalDateTime decodePacked64DatetimeSeconds(long bitFieldDatetimeSeconds) {
    checkValidBitField(bitFieldDatetimeSeconds, DATETIME_SECONDS_MASK);
    int bitFieldTimeSeconds = (int) (bitFieldDatetimeSeconds & TIME_SECONDS_MASK);
    LocalTime timeSeconds = decodePacked32TimeSeconds(bitFieldTimeSeconds);
    int year = getFieldFromBitField(bitFieldDatetimeSeconds, YEAR_MASK, YEAR_SHIFT);
    int monthOfYear = getFieldFromBitField(bitFieldDatetimeSeconds, MONTH_MASK, MONTH_SHIFT);
    int dayOfMonth = getFieldFromBitField(bitFieldDatetimeSeconds, DAY_MASK, DAY_SHIFT);
    LocalDateTime dateTime = new LocalDateTime(year, monthOfYear, dayOfMonth, timeSeconds.getHourOfDay(), timeSeconds.getMinuteOfHour(), timeSeconds.getSecondOfMinute());
    checkValidDateTimeSeconds(dateTime);
    return dateTime;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) LocalTime(org.joda.time.LocalTime)

Aggregations

LocalTime (org.joda.time.LocalTime)81 Test (org.junit.Test)39 OpeningHours (io.jawg.osmcontributor.model.utils.OpeningHours)17 LocalDate (org.joda.time.LocalDate)14 DateTime (org.joda.time.DateTime)13 LocalDateTime (org.joda.time.LocalDateTime)13 Date (java.util.Date)11 DateTimeZone (org.joda.time.DateTimeZone)10 OpeningMonth (io.jawg.osmcontributor.model.utils.OpeningMonth)6 Test (org.testng.annotations.Test)6 ArrayList (java.util.ArrayList)5 OpeningTime (io.jawg.osmcontributor.model.utils.OpeningTime)4 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 ContentValues (android.content.ContentValues)2 Time (java.sql.Time)2 EntityManager (javax.persistence.EntityManager)2 EntityTransaction (javax.persistence.EntityTransaction)2 JodaSample3 (org.datanucleus.samples.types.jodatime.JodaSample3)2 DatePickerDialog (android.app.DatePickerDialog)1 TimePickerDialog (android.app.TimePickerDialog)1