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()); }
/** * 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); }
/** * 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 JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { JsonFormat.Value format = findFormatOverrides(ctxt, property, handledType()); if (format != null) { if (format.hasPattern()) { final String pattern = format.getPattern(); final Locale locale = format.hasLocale() ? format.getLocale() : ctxt.getLocale(); DateTimeFormatter df; if (locale == null) { df = DateTimeFormatter.ofPattern(pattern); } else { df = DateTimeFormatter.ofPattern(pattern, locale); } //Issue #69: For instant serializers/deserializers we need to configure the formatter with //a time zone picked up from JsonFormat annotation, otherwise serialization might not work if (format.hasTimeZone()) { df = df.withZone(DateTimeUtils.toZoneId(format.getTimeZone())); } return withDateFormat(df); } // any use for TimeZone? } return this; } }
dtf = dtf.withZone(DateTimeUtils.toZoneId(format.getTimeZone()));