Menu

#65 Setting time fields change daylight/standard time unintentio

closed
Joda-Time (76)
6
2012-10-08
2009-01-31
No

Setting minutes with method .withMinutesOfHour() to any number that dosen't affect daylight/standard time will change from daylight time to standard time.

Example:

DateTime d = new DateTime(2009,10,25,1,59,59,999).plusMillis(1);
System.out.println(d); // 2009-10-25T02:00:00.000+02:00  +2 is correct

d = d.withMinuteOfHour(1);
System.out.println(d); // 2009-10-25T02:01:00.000+01:00  timezone changes from +2 to +1

Using .plusMinutes(1) instead the result is 2009-10-25T02:01:00.000+02:00 and the correct timezone +2.

Even if I do not change the minute (0min -> 0min) the timezone changes anyway:

d = d.withMinuteOfHour(0);
System.out.println(d); // 2009-10-25T02:00:00.000+01:00  timezone hanges from +2 to +1

The same applies to all time fields.

Discussion

  • Gerd Streubel

    Gerd Streubel - 2009-01-31

    Perhaps issue 2182444 addresses the same problem.

     
  • Stephen Colebourne

    Sadly this is a design flaw in Joda-Time that is hard to fix. JSR-310 is addressing this.

     
  • Stephen Colebourne

    Fixed in svn for v2.0.
    DateTimeZone.convertLocalToUTC [3102760,2182444,2553453]
    New method now retains the offset wherever possible during calculations
    This affects higher methods like withHourOfDay/withMinuteOfHour/withSecondOfMinute/withMillisOfSecond which now do not change offset when called within a DST overlap

     

Log in to post a comment.