I can't speak for the Joda Time programmers, but I think their
implementation is what I would expect it to be.

If you want your semantics, then you should add 365 days instead of 1 year,
that way it's always 365 days. The 1 year is implemented correctly because
if you added 28 years, then there would be many days difference from the
starting point, and this would actually be quite weird. If you want your
semantics, then add the exact days.

Ken

--
Brand New Song! Listen NOW!
http://dl.getdropbox.com/u/443421/Ken_Egervari_-_When_It_Rains.mp3

My Original Music: http://www.soundclick.com/KenEgervari
My Humorous Speeches: http://www.youtube.com/user/egervari
My Facebook:
http://www.new.facebook.com/profile.php?id=716270499/profile.php?id=716270499


On Wed, Oct 7, 2009 at 3:43 AM, Roy van Rijn <roy.van.r...@gmail.com> wrote:

> Hi all,
>
> Not so long ago we decided to ditch all the Calendar stuff and use
> Joda Time instead. But during testing our testers found a "bug" in de
> code. It has to do with leapdays and adding years. The main question
> is:
>
> If today is 29-02, what day is it when I add one year? Is it 28-02 or
> 01-03?
>
> We decided to try the Java GregorianCalendar against the two most
> logical Joda Time chronologies:
>
> -------------------------
> Chronology greChrono = GregorianChronology.getInstance();
> Chronology isoChrono = ISOChronology.getInstance();
>
> DateMidnight gregorian = new DateMidnight(2004,2,29, greChrono );
> DateMidnight iso = new DateMidnight(2004,2,29, isoChrono); //same as
> default
>
> GregorianCalendar cal = (GregorianCalendar)gregorian.toCalendar(null);
>
> //Add a year to gregoriancalendar:
> cal.roll(GregorianCalendar.YEAR, true);
> System.out.println("Gregorian Calendar:" + cal.getTime()); //Prints:
> Gregorian Calendar:Tue Mar 01 00:00:00 CET 2005
>
> //Add year to Joda:
> gregorian = gregorian.plusYears(1);
> System.out.println("JodaTime Gregorian: " + gregorian.toDate());
> //Prints: JodaTime Gregorian: Mon Feb 28 00:00:00 CET 2005
>
> iso = iso.plusYears(1);
> System.out.println("JodaTime ISO: " + iso.toDate()); //Prints:
> JodaTime ISO: Mon Feb 28 00:00:00 CET 2005
> -------------------------
>
> What is the correct method?
>
> Our testers think 01-03 is correct :-(
>
> Roy
>
>
> ------------------------------------------------------------------------------
> 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