List of usage examples for org.joda.time LocalDateTime LocalDateTime
public LocalDateTime(Object instant, Chronology chronology)
From source file:com.act.lcms.db.model.CuratedStandardMetlinIon.java
License:Open Source License
@Override protected List<CuratedStandardMetlinIon> fromResultSet(ResultSet resultSet) throws SQLException, IOException, ClassNotFoundException { List<CuratedStandardMetlinIon> results = new ArrayList<>(); while (resultSet.next()) { Integer id = resultSet.getInt(DB_FIELD.ID.getOffset()); String note = resultSet.getString(DB_FIELD.NOTE.getOffset()); LocalDateTime createdAtDate = new LocalDateTime( resultSet.getTimestamp(DB_FIELD.CREATED_AT.getOffset(), utcCalendar).getTime(), utcDateTimeZone);//from w ww .j av a 2 s . c o m String bestMetlinIon = resultSet.getString(DB_FIELD.BEST_METLIN_ION.getOffset()); Integer standardIonResultId = resultSet.getInt(DB_FIELD.STANDARD_ION_RESULT_ID.getOffset()); String author = resultSet.getString(DB_FIELD.AUTHOR.getOffset()); results.add(new CuratedStandardMetlinIon(id, note, createdAtDate, bestMetlinIon, standardIonResultId, author)); } return results; }
From source file:com.axelor.db.JpaFixture.java
License:Open Source License
@Transactional public void load(String fixture) { final InputStream stream = read(fixture); final Map<Node, Object> objects = Maps.newLinkedHashMap(); if (stream == null) { throw new IllegalArgumentException("No such fixture found: " + fixture); }/* w w w.j a va 2 s . c o m*/ final Constructor ctor = new Constructor() { { yamlClassConstructors.put(NodeId.scalar, new TimeStampConstruct()); } class TimeStampConstruct extends Constructor.ConstructScalar { Construct dateConstructor = yamlConstructors.get(Tag.TIMESTAMP); @Override public Object construct(Node nnode) { if (nnode.getTag().equals(Tag.TIMESTAMP)) { Date date = (Date) dateConstructor.construct(nnode); if (nnode.getType() == LocalDate.class) { return new LocalDate(date, DateTimeZone.UTC); } if (nnode.getType() == LocalDateTime.class) { return new LocalDateTime(date, DateTimeZone.UTC); } return new DateTime(date, DateTimeZone.UTC); } else { return super.construct(nnode); } } } @Override protected Object constructObject(Node node) { Object obj = super.constructObject(node); if (objects.containsKey(node)) { return objects.get(node); } if (obj instanceof Model) { objects.put(node, obj); return obj; } return obj; } }; for (Class<?> klass : JPA.models()) { ctor.addTypeDescription(new TypeDescription(klass, "!" + klass.getSimpleName() + ":")); } Yaml data = new Yaml(ctor); data.load(stream); for (Object item : Lists.reverse(Lists.newArrayList(objects.values()))) { try { JPA.manage((Model) item); } catch (Exception e) { } } }
From source file:com.helger.datetime.config.PDTTypeConverterRegistrar.java
License:Apache License
public void registerTypeConverter(@Nonnull final ITypeConverterRegistry aRegistry) { // Register Joda native converters _registerJodaConverter();/* ww w. jav a 2 s . co m*/ final Class<?>[] aSourceClasses = 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 aRegistry.registerTypeConverter(aSourceClasses, 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(aSourceClasses, 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(aSourceClasses, 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(aSourceClasses, 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); } }); // Period 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); } }); // MutablePeriod 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 }, MutablePeriod.class, new ITypeConverter() { @Nonnull public MutablePeriod convert(@Nonnull final Object aSource) { return new MutablePeriod(aSource); } }); }
From source file:com.helger.datetime.PDTFactory.java
License:Apache License
/** * Parse milli seconds string/* ww w. j a va 2 s .co m*/ * * @param sDateTime * A date and time as a string representation of the milli seconds * @return the {@link LocalDateTime} */ @Nonnull public static LocalDateTime createLocalDateTime(@Nonnull final String sDateTime) { return new LocalDateTime(sDateTime, getLocalChronology()); }
From source file:com.helger.datetime.PDTFactory.java
License:Apache License
@Nonnull public static LocalDateTime createLocalDateTime(@Nonnull final Date aDate, @Nonnull final DateTimeZone aDateTimeZone) { return new LocalDateTime(aDate, getLocalChronology().withZone(aDateTimeZone)); }
From source file:com.helger.datetime.PDTFactory.java
License:Apache License
@Nonnull public static LocalDateTime createLocalDateTime(@Nonnull final Calendar aCalendar) { return new LocalDateTime(aCalendar, getLocalChronology().withZone(DateTimeZone.forTimeZone(aCalendar.getTimeZone()))); }
From source file:com.helger.datetime.PDTFactory.java
License:Apache License
@Nonnull public static LocalDateTime createLocalDateTimeFromMillis(final long nMillis) { return new LocalDateTime(nMillis, getLocalChronology()); }
From source file:com.pandits.opensource.JodaTimeUtil.java
License:Open Source License
private LocalDateTime createLocalDateTime(long timeInMillis, TimeZone timeZone) { DateTimeZone dateTimeZone = findTimeZone(timeZone); LocalDateTime localDateTime = new LocalDateTime(timeInMillis, dateTimeZone); return localDateTime; }
From source file:com.phloc.datetime.config.PDTTypeConverterRegistrar.java
License:Apache License
public void registerTypeConverter(@Nonnull final ITypeConverterRegistry aRegistry) { // Register Joda native converters _registerJodaConverter();//from www .j av a 2 s . 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.querydsl.sql.types.LocalDateTimeType.java
License:Apache License
@Override public LocalDateTime getValue(ResultSet rs, int index) throws SQLException { Timestamp ts = rs.getTimestamp(index, utc()); return ts != null ? new LocalDateTime(ts.getTime(), DateTimeZone.UTC) : null; }