When adding a field would produce a bogus date, Joda-Time makes an 
adjustment to the smallest field to correct it. If Feb 29 is illegal, 
two choices are possible: Feb 28 and Mar 1. Selecting Mar 1 causes two 
fields to adjust, the day of month and month of year. Feb 28 introduces 
less error -- only the day of month changes.

We also considered choosing the error adjustment based on the direction 
of the change. That is, adding one year produces Mar 1, but subtracting 
would produce Feb 28. This might be more confusing, and it too might be 
opposite of what someone expects. No matter what we choose to use in 
Joda-Time, there's always a use case where it is not what someone expects.

One reason why the Calendar class can get away with a Mar 1 
representation for Feb 29 is because internally, the Calendar still 
thinks its Feb 29. It just displays it as Mar 1. If you subtract a year, 
you'll be back to where you started at Feb 29. With Joda-Time, 
subtracting back will yield Feb 28. This is because DateTime class 
always holds a precisely defined date. For this reason, if you're adding 
multiple years, (or any field for that matter) don't do one at a time.

roy.van.r...@gmail.com wrote:
> Oops, just noticed I'm using Dutch/European notation of days, to make 
> it clear:
> -- 
>
> Well, you can't just always add 365 days, because some years 
> (leapyears) have 366 days.
>
> The point is, if you add a year and you are in a leapyear before Feb 
> 29 you have to add 366 to get to the correct day the next year (Feb 20 
> 2004 + 366 = Feb 20 2005).
>
> And after Feb 29 you have to add 365 days to get to the correct day 
> (Mar 20 2004 + 365 = Mar 20 2005).
>
> But what should be added when you are ON Feb 29? For that I'm not 
> quite sure... it seems Java and Joda Time disagree on this. And I 
> don't have the ISO to confirm what the correct method is.
>
>
> Op 7 okt. 2009 10:19 schreef roy.van.r...@gmail.com:
> > Well, you can't just always add 365 days, because some years 
> (leapyears) have 366 days.
> >
> > The point is, if you add a year and you are in a leapyear before 
> 29-02 you have to add 366 to get to the correct day the next year 
> (20-02-2004 + 366 = 20-02-2005).
> >
> > And after 29-02 you have to add 365 days to get to the correct day 
> (20-03-2004 + 365 = 20-03-2005).
> >
> > But what should be added when you are ON 29-02? For that I'm not 
> quite sure... it seems Java and Joda Time disagree on this. And I 
> don't have the ISO to confirm what the correct method is.
> >
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay 
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> ------------------------------------------------------------------------
>
> _______________________________________________
> Joda-interest mailing list
> Joda-interest@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>   

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to