@Nonnull @Override public Instant convert(Date source) { return toInstant(source); } }
@Override public Timestamp to(ScalarInstant userObject) { return DateTimeUtils.toSqlTimestamp(userObject.getValue()); }
private ZoneId getZone(DeserializationContext context) { // Instants are always in UTC, so don't waste compute cycles return (_valueClass == Instant.class) ? null : DateTimeUtils.toZoneId(context.getTimeZone()); }
@Nonnull @Override public Date convert(LocalDateTime source) { return toDate(source.atZone(systemDefault()).toInstant()); } }
/** * Converts a {@code ZonedDateTime} to a {@code Calendar}. * <p> * The resulting {@code GregorianCalendar} is pure Gregorian and uses * ISO week definitions, starting on Monday and with 4 days in a minimal week. * <p> * Fractions of the instant smaller than milliseconds will be dropped. * * @param zdt the zoned date-time, not null * @return the calendar, not null * @throws IllegalArgumentException if the conversion fails */ public static GregorianCalendar toGregorianCalendar(ZonedDateTime zdt) { TimeZone zone = toTimeZone(zdt.getZone()); GregorianCalendar cal = new GregorianCalendar(zone); cal.setGregorianChange(new Date(Long.MIN_VALUE)); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.setMinimalDaysInFirstWeek(4); try { cal.setTimeInMillis(zdt.toInstant().toEpochMilli()); } catch (ArithmeticException ex) { throw new IllegalArgumentException(ex); } return cal; }
@Override public ScalarTime from(Time databaseObject) { return new LocalTimeScalarTime( DateTimeUtils.toLocalTime(databaseObject) ); }
@Override public ScalarDate from(Date databaseObject) { return new LocalDateScalarDate( DateTimeUtils.toLocalDate(databaseObject) ); }
@Override public Date to(ScalarDate userObject) { return DateTimeUtils.toSqlDate(userObject.getValue()); }
@Override public Time to(ScalarTime userObject) { return DateTimeUtils.toSqlTime(userObject.getValue()); }
@Nonnull @Override public Date convert(LocalDate source) { return toDate(source.atStartOfDay(systemDefault()).toInstant()); } }
/** * Converts a {@code ZonedDateTime} to a {@code Calendar}. * <p> * The resulting {@code GregorianCalendar} is pure Gregorian and uses * ISO week definitions, starting on Monday and with 4 days in a minimal week. * <p> * Fractions of the instant smaller than milliseconds will be dropped. * * @param zdt the zoned date-time, not null * @return the calendar, not null * @throws IllegalArgumentException if the conversion fails */ public static GregorianCalendar toGregorianCalendar(ZonedDateTime zdt) { TimeZone zone = toTimeZone(zdt.getZone()); GregorianCalendar cal = new GregorianCalendar(zone); cal.setGregorianChange(new Date(Long.MIN_VALUE)); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.setMinimalDaysInFirstWeek(4); try { cal.setTimeInMillis(zdt.toInstant().toEpochMilli()); } catch (ArithmeticException ex) { throw new IllegalArgumentException(ex); } return cal; }
@Override public ScalarInstant from(Timestamp databaseObject) { return new InstantScalarInstant( DateTimeUtils.toInstant(databaseObject) ); }
@Nonnull @Override public Date convert(Instant source) { return toDate(source.atZone(systemDefault()).toInstant()); } }
/** * Converts a {@code Calendar} to a {@code ZonedDateTime}. * <p> * Note that {@code GregorianCalendar} supports a Julian-Gregorian cutover * date and {@code ZonedDateTime} does not so some differences will occur. * * @param calendar the calendar, not null * @return the instant, not null */ public static ZonedDateTime toZonedDateTime(Calendar calendar) { Instant instant = Instant.ofEpochMilli(calendar.getTimeInMillis()); ZoneId zone = toZoneId(calendar.getTimeZone()); return ZonedDateTime.ofInstant(instant, zone); }
@Override public Timestamp to(ScalarInstant userObject) { return DateTimeUtils.toSqlTimestamp(userObject.getValue()); }
@Override public ScalarInstant from(Timestamp databaseObject) { return new InstantScalarInstant( DateTimeUtils.toInstant(databaseObject) ); }
@Nonnull @Override public java.time.LocalDateTime convert(LocalDateTime source) { Date date = toDate(source.atZone(ZoneId.systemDefault()).toInstant()); return Jsr310Converters.DateToLocalDateTimeConverter.INSTANCE.convert(date); } }
/** * Converts a {@code Calendar} to a {@code ZonedDateTime}. * <p> * Note that {@code GregorianCalendar} supports a Julian-Gregorian cutover * date and {@code ZonedDateTime} does not so some differences will occur. * * @param calendar the calendar, not null * @return the instant, not null */ public static ZonedDateTime toZonedDateTime(Calendar calendar) { Instant instant = Instant.ofEpochMilli(calendar.getTimeInMillis()); ZoneId zone = toZoneId(calendar.getTimeZone()); return ZonedDateTime.ofInstant(instant, zone); }
@Nonnull @Override public LocalDateTime convert(Date source) { return ofInstant(toInstant(source), systemDefault()); } }
default java.util.Date map(org.threeten.bp.LocalDate value) { return value != null ? DateTimeUtils.toDate(value.atStartOfDay(ZoneId.systemDefault()).toInstant()) : null; } }