FasterXML / jackson-datatype-joda

Extension module to properly support full datatype set of Joda datetime library
Apache License 2.0
140 stars 82 forks source link

Adjust LocalDate / LocalDateTime deserializer to support `DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE` #71

Closed nezda closed 8 years ago

nezda commented 9 years ago

When deserializing from a long, UTC should be specified to be in keeping with

http://wiki.fasterxml.com/JacksonFAQDateHandling

  • Jackson defaults to GMT/UTC ("How come this time is off by 9 hours?")

To be even more flexible, the DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE feature I wasn't aware of could be mapped from and utilized here too.

Looks like similar approach to #29 would work https://github.com/FasterXML/jackson-datatype-joda/blob/master/src/main/java/com/fasterxml/jackson/datatype/joda/deser/LocalDateDeserializer.java#L40

I'm currently "working around" this with DateTimeZone.setDefault(DateTimeZone.UTC); but this is problematic.

Test case: timestamp 1238544000000L in my timezone is 3/31/2009 but 4/1/2009 in UTC

@Test
  public void aprilFools() {
    final long aprilFools = 1238544000000L;
    System.err.println("date "+new LocalDate(aprilFools));
    System.err.println("UTC date "+new LocalDate(aprilFools, DateTimeZone.UTC));
  }