Hey!
I am developing an application that should be dst-wise. I.e. it should make difference between regular(24h), 23h and 25h days.
(my default timezone is Europe/Helsinki, 27.March.2005 at 2:59 start daylight saving time, and 31.October.2004 at 3:59 daylight saiving time ends)
Now, the problem is the following, if i am creating a Calendar representing the 31.October.2004 at 3:00, then Calendar by default treats it like wintertime date (Sun Oct 31 03:00:00 EET 2004). To mark it as summertime i set DST_OFFSET field on Calendar instance to 360000 -> Sun Oct 31 03:00:00 EEST 2004. So far, so good!
After some time of developing i faced a vry strange thing, that could be simulated by the following testcase:
This
test fails, but if line starting with XXX is uncommented, then test succeeds.
After some investigations we found that Calendar implementation has an array of flags (each element for every calendar field). Every flag may have at least 3 different values: UNSET, INTERNALLY_SET and MINIMUM_USER_STAMP. Now if i am setting DST_OFFSET by hand, then corresponding flag gets some kind of a USER_SET value and thus is never recalculated. But if i am setting time/date by setTime or setTimeInMillis, then flag of every field gets INTERNALLY_SET value and is recalculated before vital operations (for instance getTime()). This is how after line
Calendar simply forgets, that date is in summertime (because of the default behavior of Calendar for this date).
My question is, has anybody already faced this problem? Or perhaps someone can suggest antoher way of handling DST is
Java?
Thanks!