Why is 1942/4/3 00:00:00 an illegal date in java.util.Calendar?

Is there anything special about April 3, 1942? For some reason, hour day 0 (12:00 AM) is illegal for this particular date. The date is accepted when the soft calendar is used, but the hour of the day increases to 1 (1:00 in the morning).

Corresponding 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(); 

An 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 would prefer the dates not to be lenient, since I don't want to accept impossible dates.

- edit

As the accepted answer and many of the comments noted, this is indeed related to summer savings. On April 3, 1942 at 00:00, daylight saving time was checked in the EEST / Helsinki time zone. Currently, summer savings have been used since 1981, and the clock is wound at 03:00 instead of 00:00. This means that e..g March 28, 2010 03:00 a.m. does not exist in java.util.Calendar.

I just need to create custom code for this particular date in my code.

+4
source share
2 answers

Just to guess, but is this due to summer savings? I assume that this will depend on the localization of your code base (for the exact effective dates of daylight saving time), as well as other factors.

--- EDIT --- Maybe not, since it was Friday.

+6
source

Timelines and daily savings changed year after year, and 1942 was especially strange in most countries of the world - various parts changed hands quickly enough. Some parts of Asia were standardized until the "time of Burma", so they moved from local times.

Your profile says that you are in Finland, which was not so difficult. This database worldwide puts the date and time in question, since normal daylight saving time is lost within one hour.

+3
source

Source: https://habr.com/ru/post/1312966/


All Articles