I think a lot of the time, you'll want Joda to fix this automatically for you. You often donβt know the right way to correct the gap, because the size of the gap depends on the zone and year (although, of course, usually an hour).
One example of this is syntax analysis that comes from a source that you do not control; for example, networks. If the time stamp sender has stale zone files, this can happen. (If you have outdated zone files, you are very screwed up).
Here's a way to do this, which, provided, is a bit more complicated. I did this in joda 1.6 as well as 2.x since we ended up in 1.6 in our environment.
If you are building a date from some other inputs, as in your question, you can start with a UTC or LocalDate , as suggested above, and then adapt it to automatically correct the offset. A special sauce is in DateTimeZone.convertLocalToUTC
Dangerous:
public DateTime parse(String str) { formatter.parseDateTime(gapdate) }
Safe:
public DateTime parse(String str) {
I tested this in the eastern and western hemispheres, as well as in the Lord Howe Island zone, which, as it turned out, was half an hour.
It would be nice if joda formatters supported setStrict (boolean), which would make them take care of this for you ...
Jeremy Huiskamp Jul 12 '13 at 4:13 2013-07-12 04:13
source share