views:

257

answers:

2

Is there something special in the date 3rd of April 1942? For some reason the the hour of day 0 (12:00 am) is illegal for this specific date. The date is accepted when a lenient calendar is used but the hour of day is incremented to 1 (1:00 am).

Relevant code

java.util.Calendar calendar = java.util.Calendar.getInstance(
     java.util.TimeZone.getTimeZone("Europe/Helsinki")
);
calendar.clear();
calendar.setLenient(false);
calendar.set(1942, 3, 3, 0, 0, 0);
calendar.getTimeInMillis();

Exception

java.lang.IllegalArgumentException: HOUR_OF_DAY
 at java.util.GregorianCalendar.computeTime(Unknown Source)
 at java.util.Calendar.updateTime(Unknown Source)
 at java.util.Calendar.getTimeInMillis(Unknown Source)

I'd really prefer is the dates were not lenient as I don't want to accept impossible dates.

-- edit

As the accepted answer and many of the comments pointed out, this does indeed relate to daylight saving. On the 3rd of April 1942 at 00:00 daylight saving was tested in EEST/Helsinki timezone. Currently, daylight savings has been in use since 1981 and the clock is wound forward at 03:00 instead of 00:00. This means that e..g 28th of March 2010 03:00 does no exists in java.util.Calendar.

I'll just have to create a special case for this specific date in my code.

+5  A: 

Just a guess, but is it related to daylight savings? I guess that would depend on the localization of your codebase (for the exact dates of daylight savings coming into effect) as well as other factors.

---EDIT--- Maybe not, since that was a Friday.

ZombieSheep
Yeah, it was! http://stackoverflow.com/questions/1586109/hours-corrupted-when-subtract-one-day-from-gregoriancalendar is talking about the same date.
wtaniguchi
This is correct. I will accept the answer as soon as I can.
Aleksi
+3  A: 

Timezones and daylight savings varied year by year, and 1942 is a particularly odd one in much of the world - various parts of were changing hands rather rapidly. Some parts of Asia were standardised to 'Burma Time' so transitioned from local times.

Your profile says you're in Finland, which was not so complicated. This world-time database puts the date and time in question as being within one hour lost to normal daylight saving.

Pete Kirkham
The link is very intresting, thank you! I didn't even know Finland had daylight saving before 1981 before today.
Aleksi
+1 for the verification detective work (checking the OP's profile)
Lord Torgamus