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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations