Unexpected results in Period. No days returned

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Unexpected results in Period. No days returned

mschipperheyn
This post has NOT been accepted by the mailing list yet.
Hi,

I'm running into a for me very surprising issue.

I have the following code. I'm running this in Brazil.


DateTimeFormatter df = DateTimeFormat.forPattern("yyyyMMdd");

String[] dte = new String[]{"20120201","20120229"};

DateTime f = df.parseDateTime(dte[0]);
DateTime t = df.parseDateTime(dte[1]);

Period p = new Period(f,t);
int days = p.getDays();

First of all, parsing the two dates seems to result in two different time zones
f:2012-02-01T00:00:00.000-02:00
t:2012-02-29T00:00:00.000-03:00

Second and for me completely surprising, days = 0. I found out that the Period p considers itself a period of 4 weeks only (P4W) and sets all the other fields to 0.

Doesn't seem like the principal of least surprise in action to me. If getDays is not supported, it should throw some kind of error. But regardless, how do I get days to reflect the number of days accurately?

Kind regards,
Marc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unexpected results in Period. No days returned

mschipperheyn
Looks like I completely misunderstood the working of Period. This returns the accurate info

Days.daysBetween(f, t).getDays()
Loading...