The Period class divides the given period over its different fields (years,
months, weeks...). So your period will return 1 for both the getYears and
the getWeeks method as the given period of between start and end date exist
of exactly one year and one week. Therefore the getDays method will return
zero. Had the given period been one day longer, the getDays method would
have returned 1.
The toStandardXXX have their limitations because the Period only contains
the fields and not the exact start and end dates. Therefore it can not
correctly convert for example a year into a number of days (365 or 366?).

What you want is using the "SingleFieldPeriods" classes Years, Months... and
in this case Days directly.

DateTime start = new DateTime(2004, 12, 25, 0, 0, 0, 0);
DateTime end = new DateTime(2006, 1, 1, 0, 0, 0, 0);

Days days = Days.daysBetween(start, end);
System.out.println(days.getDays());

This code will give you the expected result.

Bart



On Tue, Sep 30, 2008 at 3:41 PM, Elam Daly <[EMAIL PROTECTED]> wrote:

> Hi all,
>
> I'm trying this simple example to understand the Period class.
>
> Why does the getDays() method return 0, instead of 472?
>
> Thanks,
> - Elam
>
> DateTime start = new DateTime(2004, 12, 25, 0, 0, 0, 0);
> DateTime end = new DateTime(2006, 1, 1, 0, 0, 0, 0);
>
> // period of 1 year and 7 days
> Period period = new Period(start, end);
> System.out.println(period.getDays()); // Returns 0
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Joda-interest mailing list
> Joda-interest@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to