use of org.joda.time.LocalTime in project java-driver by datastax.
the class LocalTimeCodecTest method parseParameters.
@DataProvider(name = "LocalTimeCodecTest.parse")
public Object[][] parseParameters() {
LocalTime time = LocalTime.parse("13:25:47.123456789");
String nanosOfDay = quote(Long.toString(MILLISECONDS.toNanos(time.getMillisOfDay())));
return new Object[][] { { null, null }, { "", null }, { "NULL", null }, { nanosOfDay, LocalTime.parse("13:25:47.123456789") }, { "'13:25:47'", LocalTime.parse("13:25:47") }, { "'13:25:47.123'", LocalTime.parse("13:25:47.123") }, { "'13:25:47.123456'", LocalTime.parse("13:25:47.123456") }, { "'13:25:47.123456789'", LocalTime.parse("13:25:47.123456789") } };
}
use of org.joda.time.LocalTime in project killbill by killbill.
the class DefaultInvoiceDao method notifyOfParentInvoiceCreation.
private void notifyOfParentInvoiceCreation(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final InvoiceModelDao parentInvoice, final InternalCallContext context) {
final LocalTime localTime = LocalTime.parse(invoiceConfig.getParentAutoCommitUtcTime(context));
DateTime targetFutureNotificationDate = context.getCreatedDate().withTime(localTime);
while (targetFutureNotificationDate.compareTo(context.getCreatedDate()) < 0) {
targetFutureNotificationDate = targetFutureNotificationDate.plusDays(1);
}
parentInvoiceCommitmentPoster.insertParentInvoiceFromTransactionInternal(entitySqlDaoWrapperFactory, parentInvoice.getId(), targetFutureNotificationDate, context);
}
use of org.joda.time.LocalTime in project killbill by killbill.
the class TestContiguousIntervalConsumableInArrear method testGetRolledUpUsageUsageAtTransitionTimesCancelAtBCD.
@Test(groups = "fast")
public void testGetRolledUpUsageUsageAtTransitionTimesCancelAtBCD() 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-15T11:22:30Z
final LocalDate t1 = new LocalDate(2015, 04, BCD);
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, 05, BCD), "unit", 100L, "tracking-3");
final List<RawUsageRecord> rawUsageRecord = ImmutableList.of(raw1, raw2, raw3);
final ContiguousIntervalUsageInArrear intervalConsumableInArrear = createContiguousIntervalConsumableInArrear(usage, rawUsageRecord, targetDate, true, eventT0, eventT1);
// Verify transition times
assertEquals(intervalConsumableInArrear.transitionTimes.size(), 2);
assertEquals(intervalConsumableInArrear.transitionTimes.get(0).getTargetBillingEvent().getTransitionType(), SubscriptionBaseTransitionType.CREATE);
assertEquals(intervalConsumableInArrear.transitionTimes.get(1).getTargetBillingEvent().getTransitionType(), SubscriptionBaseTransitionType.CANCEL);
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 querydsl by querydsl.
the class TypeTest method test.
@SuppressWarnings("unchecked")
@Test
public void test() throws MalformedURLException, SQLException {
List<Pair<?, ?>> valueAndType = new ArrayList<Pair<?, ?>>();
valueAndType.add(Pair.of(new BigDecimal("1"), new BigDecimalType()));
valueAndType.add(Pair.of(new BigInteger("2"), new BigIntegerType()));
valueAndType.add(Pair.of(new BigDecimal("1.0"), new BigDecimalAsDoubleType()));
valueAndType.add(Pair.of(new BigInteger("2"), new BigIntegerAsLongType()));
// valueAndType.add(Pair.of(Boolean.TRUE, new BooleanType()));
valueAndType.add(Pair.of((byte) 1, new ByteType()));
valueAndType.add(Pair.of(new byte[0], new BytesType()));
valueAndType.add(Pair.of(Calendar.getInstance(), new CalendarType()));
valueAndType.add(Pair.of('c', new CharacterType()));
valueAndType.add(Pair.of(Currency.getInstance("EUR"), new CurrencyType()));
valueAndType.add(Pair.of(new java.sql.Date(0), new DateType()));
valueAndType.add(Pair.of(1.0, new DoubleType()));
valueAndType.add(Pair.of(1.0f, new FloatType()));
valueAndType.add(Pair.of(1, new IntegerType()));
valueAndType.add(Pair.of(true, new NumericBooleanType()));
valueAndType.add(Pair.of(1L, new LongType()));
valueAndType.add(Pair.of(new Object(), new ObjectType()));
valueAndType.add(Pair.of((short) 1, new ShortType()));
valueAndType.add(Pair.of("", new StringType()));
valueAndType.add(Pair.of(true, new TrueFalseType()));
valueAndType.add(Pair.of(true, new YesNoType()));
valueAndType.add(Pair.of(new Timestamp(0), new TimestampType()));
valueAndType.add(Pair.of(new Time(0), new TimeType()));
valueAndType.add(Pair.of(new URL("http://www.mysema.com"), new URLType()));
valueAndType.add(Pair.of(new java.util.Date(), new UtilDateType()));
valueAndType.add(Pair.of(new DateTime(), new DateTimeType()));
valueAndType.add(Pair.of(new LocalDateTime(), new LocalDateTimeType()));
valueAndType.add(Pair.of(new LocalDate(), new LocalDateType()));
valueAndType.add(Pair.of(new LocalTime(), new LocalTimeType()));
valueAndType.add(Pair.of(Gender.MALE, new EnumByNameType<Gender>(Gender.class)));
valueAndType.add(Pair.of(Gender.MALE, new EnumByOrdinalType<Gender>(Gender.class)));
valueAndType.add(Pair.of(EasyMock.createNiceMock(Blob.class), new BlobType()));
valueAndType.add(Pair.of(EasyMock.createNiceMock(Clob.class), new ClobType()));
valueAndType.add(Pair.of(UUID.randomUUID(), new UtilUUIDType(true)));
valueAndType.add(Pair.of(UUID.randomUUID(), new UtilUUIDType(false)));
for (Pair pair : valueAndType) {
value = null;
Type type = (Type) pair.getSecond();
assertNull(type.toString(), type.getValue(resultSet, 0));
type.setValue(statement, 0, pair.getFirst());
assertEquals(type.toString(), pair.getFirst(), type.getValue(resultSet, 0));
}
}
use of org.joda.time.LocalTime in project tests by datanucleus.
the class JodaTimeTest method testQueryLocalTime.
/**
* Test for LocalTime persistence and retrieval.
*/
public void testQueryLocalTime() {
try {
// Create some data we can use for access
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
LocalTime localTime1 = new LocalTime(15, 9, 26);
LocalTime localTime2 = new LocalTime(7, 9, 26);
try {
tx.begin();
JodaSample3 s1 = new JodaSample3(1, localTime1, localTime1);
em.persist(s1);
JodaSample3 s2 = new JodaSample3(2, localTime2, localTime2);
em.persist(s2);
tx.commit();
} catch (Exception e) {
LOG.error("Error persisting LocalTime sample", e);
fail("Error persisting LocalTime sample");
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
// Retrieve the data
em = emf.createEntityManager();
tx = em.getTransaction();
try {
tx.begin();
Query q = em.createQuery("SELECT s FROM " + JodaSample3.class.getName() + " s WHERE s.localTime1 < :timeParam");
LocalTime timeParam = new LocalTime(11, 9, 26);
q.setParameter("timeParam", timeParam);
List<JodaSample3> results = q.getResultList();
assertEquals("Number of results is wrong", 1, results.size());
JodaSample3 s = results.get(0);
LocalTime lt1 = s.getLocalTime1();
assertNotNull("Retrieved LocalTime was null!", lt1);
assertEquals("Hour was wrong", 7, lt1.getHourOfDay());
assertEquals("Minute was wrong", 9, lt1.getMinuteOfHour());
assertEquals("Second was wrong", 26, lt1.getSecondOfMinute());
tx.commit();
} catch (Exception e) {
LOG.error("Error retrieving LocalTime data", e);
fail("Error retrieving LocalTime data : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(JodaSample3.class);
}
}
Aggregations