Thanks for the test case. This issue only occurs when a timezone changes 
  for the FIRST time from being 'undefined' to a fixed amount.

ExpectedMonth=1
   ActualMonth=12
           LastDT=1911-12-01T00:00:00.000-00:16:08
         ActualDT=1911-12-31T23:43:52.000-00:16:08
ZoneChangeBefore=1911-12-31T23:43:51.999-00:16:08
  ZoneChangeAfter=1912-01-01T00:16:08.001Z
NOK;Africa/Abidjan;Africa/Abidjan

It also occurs because the new value of 1912-01-01T00:00:00.001Z doesn't 
exist (due to the timezone change).

I'm not sure we can do much about this, as we can't return a time that 
doesn't exist.

Stephen


Walter Sarka wrote:
> Thanks for your quick answers, Stephen!
> 
> 
>>You might want to consider writing a test case that loops through time
>>adding a month, seeing if the time fields stay contant (using
>>different zones)
> 
> This is how I discovered the problem (in principle... in fact I did
> some more complicated things where the described behaviour was a side
> effect).
> The "time fields" (hour, minute, second, I suppose) must change if the
> time does not exist due to DST (throwing an exception would be the
> alternative).
>>From my point of view the month of year must *always* increase while
> looping with plusMonths() (except the Dec -> Jan switch).
> 
> Looking at DateTimeField.set(long instant, int value) the time fields
> can change under defined circumstances:
> <javadoc>
>      * If setting this field would make other fields invalid, then those 
> fields
>      * may be changed. For example if the current date is the 31st January, 
> and
>      * the month is set to February, the day would be invalid. Instead, the 
> day
>      * would be changed to the closest value - the 28th/29th February
> as appropriate.
> </javadoc>
> 
> May be the behaviour of DateTime.plusMonths() depends on the
> documented behaviour of DateTimeField.set() (I know too few about
> Joda)?
> However, this is not the result an API user would expect from plusMonths().
> 
> The result from the test methods below was: in 130 of 537 timezones
> the "error" occurred.
> 
>     public void testPlusMonths() {
>         Object[] allTimeZones = DateTimeZone.getAvailableIDs().toArray();
>         System.out.println("OK state;Timezone Alias;Timezone name");
>         for (Object tz : allTimeZones) {
>             plusMonths((String)tz);
>         }
>     }
> 
>     private void plusMonths(String tzId) {
> 
>         setTimezone(tzId);
> 
>         DateTime startDate;
>         boolean ok = true;
>         for (int hr = 0; hr < 24; hr++) {
>             try {
>                 startDate = new DateTime(1900, 1, 1, hr, 0, 0, 0);
>             } catch (IllegalArgumentException e) {
>                 // DateTime does not exist, due to timezone offset transition
>                 continue;
>             }
>             if (plusMonthsWith(startDate) == false) {
>                 ok = false;
>                 break;
>             }
>         }
> 
>         if (!ok) {
>             System.out.println("NOK;" +
> DateTimeZone.getDefault().getID() + ";" + tzId);
>         } else {
>             System.out.println("OK;" +
> DateTimeZone.getDefault().getID() + ";" + tzId);
>         }
>     }
> 
>     private boolean plusMonthsWith(DateTime startDate) {
> 
>         int latestMonth = startDate.getMonthOfYear();
>         int expectedMonth;
>         DateTime dt = startDate.toDateTime();
>         boolean ok = true;
>         for (int i=0; i<2000; i++) {
>             latestMonth = dt.getMonthOfYear();
>             dt = dt.plusMonths(1);
>             if (latestMonth==12) {
>                 expectedMonth = 1;
>             } else {
>                 expectedMonth = latestMonth+1;
>             }
>             //assertEquals(expectedMonth, dt.getMonthOfYear());
>             if (expectedMonth != dt.getMonthOfYear()) {
>                 ok = false;
>                 break;
>             }
>         }
> 
>         return ok;
>     }
> 
>     private void setTimezone(String id) {
>         DateTimeZone.setDefault(DateTimeZone.forID(id));
>         
> TimeZone.setDefault(TimeZone.getTimeZone(DateTimeZone.getDefault().getID()));
>     }
> 
> 
> On 7/18/06, Stephen Colebourne <[EMAIL PROTECTED]> wrote:
> 
>>Well, its not something that I've seen before. Until I have time to
>>examine the code I can't really comment further.
>>
>>You might want to consider writing a test case that loops through time
>>adding a month, seeing if the time fields stay contant (using
>>different zones)
>>
>>And of course, you're welcome to download the Joda-Time source and
>>take a look there :-)
>>
>>Stephen
>>
>>On 18/07/06, Walter Sarka <[EMAIL PROTECTED]> wrote:
>>
>>>Some additional information under which circumstances the bug occurs
>>>would be *very* helpful. E.g. if the bug occurs only for some "exotic"
>>>(defineable) timezones, it would be a minor problem for me (and e.g.
>>>not require a rewrite of large parts of the code using Joda).
>>>
>>>Just for correctness, in the sentence in my initial posting:
>>>
>>>>Is this a bug or a defined behaviour (probably due to DST, since
>>>>"1979-10-01T23:20:00.000-10:40" is not defined for the timezone
>>>>above)?
>>>
>>>it should read "1979-10-01T00:00:00.000-10:40" instead.
>>>
>>>Walter
>>>
>>>
>>>On 7/18/06, Stephen Colebourne <[EMAIL PROTECTED]> wrote:
>>>
>>>>1979-09-01 + 1 month = 1979-10-01
>>>>so, it looks at first glance like a bug.
>>>>
>>>>Stephen
>>>>
>>>>On 18/07/06, Walter Sarka <[EMAIL PROTECTED]> wrote:
>>>>
>>>>>I have a DateTime dt.
>>>>>dt.toString() is "1979-09-01T00:00:00.000-10:40"
>>>>>Then I add a month: dtNew = DateTime.plusMonths(1);
>>>>>dtNew.toString() now is "1979-09-30T23:20:00.000-10:40".
>>>>>The joda default timezone is "Pacific/Kiritimati".
>>>>>
>>>>>I expected dtNew to be "1979-10-01...", as the naming plusMonths() 
>>>>>suggests.
>>>>>
>>>>>Is this a bug or a defined behaviour (probably due to DST, since
>>>>>"1979-10-01T23:20:00.000-10:40" is not defined for the timezone
>>>>>above)?
>>>>>
>>>>>If it is a bug: does it only occur with "exotic" timezones or can it
>>>>>happen at every DST transition?
>>>>>
>>>>>Can you give me some hints how to get "1979-10-01T..." (preferably
>>>>>with the lowest defined time of day) for dtNew?
>>>>>I suppose adding days till reaching October, but may be there is a far
>>>>>better solution, since such behaviour can happen in all places where
>>>>>adding or subtracting.
>>>>>
>>>>>Thanks, Walter.
>>>>>
>>>>>-------------------------------------------------------------------------
>>>>>Take Surveys. Earn Cash. Influence the Future of IT
>>>>>Join SourceForge.net's Techsay panel and you'll get the chance to share 
>>>>>your
>>>>>opinions on IT & business topics through brief surveys -- and earn cash
>>>>>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>>>>>_______________________________________________
>>>>>Joda-interest mailing list
>>>>>[email protected]
>>>>>https://lists.sourceforge.net/lists/listinfo/joda-interest
>>>>>
>>>>
>>>>-------------------------------------------------------------------------
>>>>Take Surveys. Earn Cash. Influence the Future of IT
>>>>Join SourceForge.net's Techsay panel and you'll get the chance to share your
>>>>opinions on IT & business topics through brief surveys -- and earn cash
>>>>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>>>>_______________________________________________
>>>>Joda-interest mailing list
>>>>[email protected]
>>>>https://lists.sourceforge.net/lists/listinfo/joda-interest
>>>>
>>>
>>>-------------------------------------------------------------------------
>>>Take Surveys. Earn Cash. Influence the Future of IT
>>>Join SourceForge.net's Techsay panel and you'll get the chance to share your
>>>opinions on IT & business topics through brief surveys -- and earn cash
>>>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>>>_______________________________________________
>>>Joda-interest mailing list
>>>[email protected]
>>>https://lists.sourceforge.net/lists/listinfo/joda-interest
>>>
>>
>>-------------------------------------------------------------------------
>>Take Surveys. Earn Cash. Influence the Future of IT
>>Join SourceForge.net's Techsay panel and you'll get the chance to share your
>>opinions on IT & business topics through brief surveys -- and earn cash
>>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>>_______________________________________________
>>Joda-interest mailing list
>>[email protected]
>>https://lists.sourceforge.net/lists/listinfo/joda-interest
>>
> 
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Joda-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
> 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to