Wednesday, April 13, 2016

LocalDateTime Is Not Local!

No one ever has problems with Dates and Times!  (Y2k, 2038, 10,000)

Java8 dates and times were supposed to be a lot easier and designed by the Joda-Time guys.

One problem, after struggling for a full working day - LocalDateTimes are NOT Local!  Maybe in the sense of localized?  They are definitely UTC, not your local timezone.  Looking back at it, it says that it doesn't capture timezone information in the docs, but I didn't look at the docs because I thought that the name was blindingly obvious.

Copyright BBC
I was pulling my hair out when I wrote a function todayAt that returned a date that didn't register as today.  A time at 3:45 PM was being converted to 2 AM UTC (the next day) because LocalDateTime wasn't local.  I was looking for ZonedDateTime.

As they say, there are two hard things in Computer Science: caching, naming things and off by one errors.

No comments:

Post a Comment