The real WTF is history.



  • Had this come up as a complaint from production: adding a new customer born in 1945 failed, the birthdate was not accepted.

    Try running the code below on a Sun Java 1.4 system.

    import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone;

    public class DateTest
    {
    public static void main(String[] args) throws Exception
    {
    mung("25.09.1945", "Europe/Rome");
    mung("24.09.1945", "Europe/Rome");
    mung("25.09.1945", "Europe/Berlin");
    mung("24.09.1945", "Europe/Berlin");
    }

    public static void mung(String date, String timeZone) throws Exception
    {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
        GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone(timeZone));
        calendar.setLenient(false);
        calendar.setTime(dateFormat.parse(date));
        calendar.set(Calendar.MILLISECOND, 0);
        System.out.println(timeZone + " - " + calendar.getTime());
    }
    

    }

    It will fail on the last call of the mung() method, on the Calendar.getTime() call.

    Turns out this is a bug in the JDK based on a history WTF. In summer 1945, Berlin and the Soviet-occupied part of Germany observed a daylight savings time of two hours. Unfortunately, Sun's JRE 1.4 implementation of GregorianCalendar defines a maximum DST of one hour and, in non-lenient mode, rejects the 2 hours as invalid when recalculating all fields after the millisecond field is set.



  • <insert standard forum software WTF comment>



    Had this come up as a complaint from production: adding a new customer born in 1945 failed, the birthdate was not accepted.

    Try running the code below on a Sun Java 1.4 system.



    import java.text.SimpleDateFormat;

    import java.util.Calendar;

    import java.util.GregorianCalendar;

    import java.util.TimeZone;





    public class DateTest

    {

        public static void main(String[] args) throws Exception

        {

            mung("25.09.1945", "Europe/Rome");

            mung("24.09.1945", "Europe/Rome");       

            mung("25.09.1945", "Europe/Berlin");

            mung("24.09.1945", "Europe/Berlin");       

        }

       

        public static void mung(String date, String timeZone) throws Exception

        {

            SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");

            GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone(timeZone));

            calendar.setLenient(false);

            calendar.setTime(dateFormat.parse(date));

            calendar.set(Calendar.MILLISECOND, 0);

            System.out.println(timeZone + " - " + calendar.getTime());

        }

    }





    It will fail on the last call of the mung() method, on the Calendar.getTime() call.

    Turns out this is a bug in the JDK based on a history WTF. In summer 1945, Berlin and the Soviet-occupied part of Germany observed a daylight savings time of two hours.
    Unfortunately, Sun's JRE 1.4 implementation of GregorianCalendar
    defines a maximum DST of one hour and, in non-lenient mode, rejects the
    2 hours as invalid when recalculating all fields after the millisecond
    field is set.



  • I wonder if that included West Berlin?



  • @marvin_rabbit said:

    I wonder if that included West Berlin?




    At that time, just months after the end of WWII, there was no West
    Berlin, there was an American, a British, a French and a Soviet
    occupied zone, both for Berlin and for Germany as a whole.



    Apparently the Soviets come up with the idea for their zones, and the
    other allies also implemented it for their parts of Berlin, since
    having a timezone difference of one hour within the city would have
    been rather perverse. So it included both what would later become East
    Germany and what would become West Berlin.




  • @brazzy said:

    @marvin_rabbit said:
    I wonder if that included West Berlin?




    At that time, just months after the end of WWII, there was no West
    Berlin, there was an American, a British, a French and a Soviet
    occupied zone, both for Berlin and for Germany as a whole.



    Apparently the Soviets come up with the idea for their zones, and the
    other allies also implemented it for their parts of Berlin, since
    having a timezone difference of one hour within the city would have
    been rather perverse. So it included both what would later become East
    Germany and what would become West Berlin.




    I guess it wasn't DST, but Moscow time zone.



  • @brazzy said:

    Turns out this is a bug in the JDK based on a history WTF. In summer 1945, Berlin and the Soviet-occupied part of Germany observed a daylight savings time of two hours.
    Unfortunately, Sun's JRE 1.4 implementation of GregorianCalendar
    defines a maximum DST of one hour and, in non-lenient mode, rejects the
    2 hours as invalid when recalculating all fields after the millisecond
    field is set.

    They're not the only ones; Britain apparently has something called British Double Summer Time for a while during/after WWII. I doubt there's much software out there that can handle that correctly...



  • According to Wikipedia, Newfoundland used a 2-hour jump as recently as 1988.



  • @brazzy said:

    @marvin_rabbit said:
    I wonder if that included West Berlin?




    At that time, just months after the end of WWII, there was no West
    Berlin, there was an American, a British, a French and a Soviet
    occupied zone, both for Berlin and for Germany as a whole.



    Apparently the Soviets come up with the idea for their zones, and the
    other allies also implemented it for their parts of Berlin, since
    having a timezone difference of one hour within the city would have
    been rather perverse. So it included both what would later become East
    Germany and what would become West Berlin.



    Ah, of course.  I lost track of when the 'sectors' became East/West.  So you both answered my question, and set my fuzzy history straight.  Thanks!



  • Nice catch. That must be the most obscure bug I've ever heard of.

    I blame communism.



  • Just to be clear, we aren't blaming this on Java, are we?



    Actually, as somebody who lives in the Canadian province of
    Saskatchewan, I'd like to say that daylight savings time is the real
    WTF.



    AFAIK, it was invented right here in Saskatchewan to aid farmers whose
    workday followed the sun, and during the summer their work hours were
    significantly different than those of everybody else.  So, shift
    the "time" to line up with the sun's patterns and all is well.



    Since then we are now one of the few places in the world who do NOT use
    daylight savings time.  If we invented it for our own benefit, and
    decided it was pointless enough to drop it, why does the rest of the
    world keep using it?  The only logical answer I can comprehend is
    that, having adopted (for the same fallacious reasons that we did),
    it's more of a hassle to try and change back than to just live with
    it.  Probably the same reason why every now and then the idea
    comes up here to re-adopt DST (namely, that the time difference between
    us and everybody else changes twice a year).



    A great example of the problem of backwards compatiability. 
    "Nobody said it was a good idea, but it's more trouble to fix it than
    it is to just deal with it."



  • @RevEng said:

    Just to be clear, we aren't blaming this on Java, are we?




    Yes, we are. Not allowing DST of 2 hours is a bug in Java 1.4. It was
    not present in 1.3, and it was fixed for 1.5. Here's the bug report:



    As for who invented daylight savings time, it was the Irish, in 1916,
    though the first to implement it were the Germans. The reason was to
    save power on lighting, which is why it was implemented in the two
    world wars and again after the 1973 oil crisis. And no, it doesn't
    really have the desired effect.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.