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
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest