List of usage examples for org.joda.time LocalDate LocalDate
public LocalDate(Object instant, Chronology chronology)
From source file:com.ning.billing.invoice.generator.DefaultInvoiceGenerator.java
License:Apache License
InvoiceItem generateFixedPriceItem(final UUID invoiceId, final UUID accountId, final BillingEvent thisEvent, final LocalDate targetDate, final Currency currency) { final LocalDate roundedStartDate = new LocalDate(thisEvent.getEffectiveDate(), thisEvent.getTimeZone()); if (roundedStartDate.isAfter(targetDate)) { return null; } else {// w w w .j ava2 s . c o m final BigDecimal fixedPrice = thisEvent.getFixedPrice(); if (fixedPrice != null) { return new FixedPriceInvoiceItem(invoiceId, accountId, thisEvent.getSubscription().getBundleId(), thisEvent.getSubscription().getId(), thisEvent.getPlan().getName(), thisEvent.getPlanPhase().getName(), roundedStartDate, fixedPrice, currency); } else { return null; } } }
From source file:com.ning.billing.util.clock.ClockMock.java
License:Apache License
@Override public LocalDate getToday(final DateTimeZone timeZone) { return new LocalDate(getUTCNow(), timeZone); }
From source file:com.ning.billing.util.clock.DefaultClock.java
License:Apache License
@Override public LocalDate getToday(final DateTimeZone timeZone) { return new LocalDate(getUTCNow(), DateTimeZone.UTC); }
From source file:com.ning.billing.util.clock.OldClockMock.java
License:Apache License
@Override public LocalDate getUTCToday() { return new LocalDate(getUTCNow(), DateTimeZone.UTC); }
From source file:com.ning.billing.util.dao.LowerToCamelBeanMapper.java
License:Apache License
public T map(final int row, final ResultSet rs, final StatementContext ctx) throws SQLException { final T bean; try {//from w ww . j ava2 s .co m bean = type.newInstance(); } catch (Exception e) { throw new IllegalArgumentException( String.format("A bean, %s, was mapped " + "which was not instantiable", type.getName()), e); } final Class beanClass = bean.getClass(); final ResultSetMetaData metadata = rs.getMetaData(); for (int i = 1; i <= metadata.getColumnCount(); ++i) { final String name = metadata.getColumnLabel(i).toLowerCase(); final PropertyDescriptor descriptor = properties.get(name); if (descriptor != null) { final Class<?> type = descriptor.getPropertyType(); Object value; if (type.isAssignableFrom(Boolean.class) || type.isAssignableFrom(boolean.class)) { value = rs.getBoolean(i); } else if (type.isAssignableFrom(Byte.class) || type.isAssignableFrom(byte.class)) { value = rs.getByte(i); } else if (type.isAssignableFrom(Short.class) || type.isAssignableFrom(short.class)) { value = rs.getShort(i); } else if (type.isAssignableFrom(Integer.class) || type.isAssignableFrom(int.class)) { value = rs.getInt(i); } else if (type.isAssignableFrom(Long.class) || type.isAssignableFrom(long.class)) { value = rs.getLong(i); } else if (type.isAssignableFrom(Float.class) || type.isAssignableFrom(float.class)) { value = rs.getFloat(i); } else if (type.isAssignableFrom(Double.class) || type.isAssignableFrom(double.class)) { value = rs.getDouble(i); } else if (type.isAssignableFrom(BigDecimal.class)) { value = rs.getBigDecimal(i); } else if (type.isAssignableFrom(DateTime.class)) { final Timestamp timestamp = rs.getTimestamp(i); value = timestamp == null ? null : new DateTime(timestamp).toDateTime(DateTimeZone.UTC); } else if (type.isAssignableFrom(Time.class)) { value = rs.getTime(i); } else if (type.isAssignableFrom(LocalDate.class)) { final Date date = rs.getDate(i); value = date == null ? null : new LocalDate(date, DateTimeZone.UTC); } else if (type.isAssignableFrom(DateTimeZone.class)) { final String dateTimeZoneString = rs.getString(i); value = dateTimeZoneString == null ? null : DateTimeZone.forID(dateTimeZoneString); } else if (type.isAssignableFrom(String.class)) { value = rs.getString(i); } else if (type.isAssignableFrom(UUID.class)) { final String uuidString = rs.getString(i); value = uuidString == null ? null : UUID.fromString(uuidString); } else if (type.isEnum()) { final String enumString = rs.getString(i); //noinspection unchecked value = enumString == null ? null : Enum.valueOf((Class<Enum>) type, enumString); } else { value = rs.getObject(i); } if (rs.wasNull() && !type.isPrimitive()) { value = null; } try { final Method writeMethod = descriptor.getWriteMethod(); if (writeMethod != null) { writeMethod.invoke(bean, value); } else { final String camelCasedName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name); final Field field = getField(beanClass, camelCasedName); field.setAccessible(true); // Often private... field.set(bean, value); } } catch (NoSuchFieldException e) { throw new IllegalArgumentException( String.format("Unable to find field for " + "property, %s", name), e); } catch (IllegalAccessException e) { throw new IllegalArgumentException( String.format("Unable to access setter for " + "property, %s", name), e); } catch (InvocationTargetException e) { throw new IllegalArgumentException(String.format( "Invocation target exception trying to " + "invoker setter for the %s property", name), e); } catch (NullPointerException e) { throw new IllegalArgumentException( String.format("No appropriate method to " + "write value %s ", value.toString()), e); } } } return bean; }
From source file:com.ning.billing.util.dao.MapperBase.java
License:Apache License
protected LocalDate getDate(final ResultSet rs, final String fieldName) throws SQLException { final Date resultStamp = rs.getDate(fieldName); return rs.wasNull() ? null : new LocalDate(resultStamp, DateTimeZone.UTC); }
From source file:com.phloc.datetime.config.PDTTypeConverterRegistrar.java
License:Apache License
public void registerTypeConverter(@Nonnull final ITypeConverterRegistry aRegistry) { // Register Joda native converters _registerJodaConverter();/* w w w . ja v a2s .c o m*/ // DateTime aRegistry.registerTypeConverter( new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, DateTime.class, new ITypeConverter() { @Nonnull public DateTime convert(@Nonnull final Object aSource) { return new DateTime(aSource, PDTConfig.getDefaultChronology()); } }); aRegistry.registerTypeConverter(LocalDate.class, DateTime.class, new ITypeConverter() { @Nonnull public DateTime convert(@Nonnull final Object aSource) { return PDTFactory.createDateTime((LocalDate) aSource); } }); aRegistry.registerTypeConverter(LocalTime.class, DateTime.class, new ITypeConverter() { @Nonnull public DateTime convert(@Nonnull final Object aSource) { return PDTFactory.createDateTime((LocalTime) aSource); } }); aRegistry.registerTypeConverter(LocalDateTime.class, DateTime.class, new ITypeConverter() { @Nonnull public DateTime convert(@Nonnull final Object aSource) { return PDTFactory.createDateTime((LocalDateTime) aSource); } }); // LocalDateTime aRegistry.registerTypeConverter( new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, LocalDateTime.class, new ITypeConverter() { @Nonnull public LocalDateTime convert(@Nonnull final Object aSource) { return new LocalDateTime(aSource, PDTConfig.getDefaultChronology()); } }); aRegistry.registerTypeConverter(DateTime.class, LocalDateTime.class, new ITypeConverter() { @Nonnull public LocalDateTime convert(@Nonnull final Object aSource) { return PDTFactory.createLocalDateTime((DateTime) aSource); } }); aRegistry.registerTypeConverter(LocalDate.class, LocalDateTime.class, new ITypeConverter() { @Nonnull public LocalDateTime convert(@Nonnull final Object aSource) { return PDTFactory.createLocalDateTime((LocalDate) aSource); } }); aRegistry.registerTypeConverter(LocalTime.class, LocalDateTime.class, new ITypeConverter() { @Nonnull public LocalDateTime convert(@Nonnull final Object aSource) { return PDTFactory.createLocalDateTime((LocalTime) aSource); } }); // LocalDate aRegistry.registerTypeConverter( new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, LocalDate.class, new ITypeConverter() { @Nonnull public LocalDate convert(@Nonnull final Object aSource) { return new LocalDate(aSource, PDTConfig.getDefaultChronology()); } }); aRegistry.registerTypeConverter(DateTime.class, LocalDate.class, new ITypeConverter() { @Nonnull public LocalDate convert(@Nonnull final Object aSource) { return PDTFactory.createLocalDate((DateTime) aSource); } }); aRegistry.registerTypeConverter(LocalDateTime.class, LocalDate.class, new ITypeConverter() { @Nonnull public LocalDate convert(@Nonnull final Object aSource) { return PDTFactory.createLocalDate((LocalDateTime) aSource); } }); // LocalTime aRegistry.registerTypeConverter( new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, LocalTime.class, new ITypeConverter() { @Nonnull public LocalTime convert(@Nonnull final Object aSource) { return new LocalTime(aSource, PDTConfig.getDefaultChronology()); } }); aRegistry.registerTypeConverter(DateTime.class, LocalTime.class, new ITypeConverter() { @Nonnull public LocalTime convert(@Nonnull final Object aSource) { return PDTFactory.createLocalTime((DateTime) aSource); } }); aRegistry.registerTypeConverter(LocalDateTime.class, LocalTime.class, new ITypeConverter() { @Nonnull public LocalTime convert(@Nonnull final Object aSource) { return PDTFactory.createLocalTime((LocalDateTime) aSource); } }); // Duration aRegistry.registerTypeConverter(new Class<?>[] { String.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, Duration.class, new ITypeConverter() { @Nonnull public Duration convert(@Nonnull final Object aSource) { return new Duration(aSource); } }); // Duration aRegistry.registerTypeConverter(new Class<?>[] { String.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, Period.class, new ITypeConverter() { @Nonnull public Period convert(@Nonnull final Object aSource) { return new Period(aSource); } }); }
From source file:com.phloc.datetime.PDTFactory.java
License:Apache License
@Nonnull public static LocalDate createLocalDate(@Nonnull final Date aDate, final TimeZone aTimeZone) { return new LocalDate(aDate, getLocalChronology().withZone(DateTimeZone.forTimeZone(aTimeZone))); }
From source file:com.querydsl.sql.types.LocalDateType.java
License:Apache License
@Override public LocalDate getValue(ResultSet rs, int startIndex) throws SQLException { Date date = rs.getDate(startIndex, utc()); return date != null ? new LocalDate(date.getTime(), DateTimeZone.UTC) : null; }