Menu

#175 addDays(0) changes value of MutableDateTime

v1.0_(example)
open
nobody
None
1
2015-01-23
2013-10-16
werner
No

Upon DST transition from summer to winter time zone, adding the amount of zero days to a mutable date time object changes the value of the object.

The code

final MutableDateTime mdt = new MutableDateTime(2011, 10, 30, 3, 0, 0, 0, DateTimeZone.forID("Europe/Berlin"));
System.out.println("Start date:   " + mdt + " (" + mdt.toInstant().getMillis() + ")");
mdt.addHours(-1);
System.out.println("addHours(-1): " + mdt + " (" + mdt.toInstant().getMillis() + ")");
mdt.addHours(0);
System.out.println("addHours(0):  " + mdt + " (" + mdt.toInstant().getMillis() + ")");
mdt.addDays(0);
System.out.println("addDays(0):   " + mdt + " (" + mdt.toInstant().getMillis() + ")");

prints

Start date:   2011-10-30T03:00:00.000+01:00 (1319940000000)    //OK
addHours(-1): 2011-10-30T02:00:00.000+01:00 (1319936400000)    //OK
addHours(0):  2011-10-30T02:00:00.000+01:00 (1319936400000)    //OK, no change in time
addDays(0):   2011-10-30T02:00:00.000+02:00 (1319932800000)    //error, time has changed by 1 hour

The methods addMonths and addYears show the same problem; addSeconds, addMinntes and addHours are ok.

I have tested with version 2.3. However, if I repeat the test with Joda 1.5.2, the invocation of addDays(0) does not change the date's value.

Discussion

  • werner

    werner - 2013-10-16

    Bug added at GitHub

     

Log in to post a comment.

MongoDB Logo MongoDB