Hi Gareth,
When you convert to a DateMidnight, you add in a timezone - the defaault 
for your box. If your test crosses a DST boundary, then the length of a 
day may be 23 or 25 hours. Also, when converting to a DateMidnight, the 
date may not actually have a time at midnight (due to DST rules).

All these factors combine to mean that the comparison differs for 
DateMidnight and LocalDate. The exception is if you setup the 
DateMidnight with the UTC timezone - then you will get the same result.

Stephen


[EMAIL PROTECTED] wrote:
> I have been looking into joda time and am finding it considerably easier
> to work with than Date, Calendar, etc.
> 
> However, I have come across the following issue with the latest release
> version.  I've searched the mailing list but can't see any mention of
> it.
> 
> Is the following inconsistency a bug or a feature?
> 
> Code:
>         LocalDate today = new LocalDate();
>         LocalDate futureDay = today.plusDays(5);
>                
>         // Method 1:
>         Days days1 = Days.daysBetween(today,futureDay);
>         
>         // Method 2:
>         DateMidnight dmToday = today.toDateMidnight();
>         DateMidnight dmFutureDay = futureDay.toDateMidnight();
>         Days days2 = Days.daysBetween(dmToday,dmFutureDay);
>         
>         // Method 3:       
>         Period period = new Period(today, futureDay);
>         
>         System.out.println("Method 1 = " + days1.getDays() + " days.");
>         System.out.println("Method 2 = " + days2.getDays() + " days.");
>         System.out.println("Method 3 = " + period.getDays() + " days.");
> 
> Output:
> 
> Method 1 = 4 days.
> Method 2 = 5 days.
> Method 3 = 5 days.
> 
> The first method is the most intuitive and the one I would like to use,
> however when calculating the number of days from today until a certain
> date, it gives the incorrect answer (I appreciate "days between" is open
> to interpretation, although method 2 uses the same method).  2 and 3
> both give the desired result.
> 
> Based on the following quote I would expect methods 1 and 2 to give the
> same results:
> 
>> ** Stephen Colebourne <[EMAIL PROTECTED]> wrote **
>>
>>
>> Replying quickly...
>>
>> A LocalDate and a DateMidnight in UTC ought to be effectively
> identical,
>> as they are internally.
> 
> The same seems to happen for finding years between two dates as well as
> days.
> 
> Many thanks,
> 
> Gareth
> 
> 
> PLEASE READ: The information contained in this email is confidential and
> intended for the named recipient(s) only. If you are not an intended
> recipient of this email please notify the sender immediately and delete your
> copy from your system. You must not copy, distribute or take any further
> action in reliance on it. Email is not a secure method of communication and
> Nomura International plc ('NIplc') will not, to the extent permitted by law,
> accept responsibility or liability for (a) the accuracy or completeness of,
> or (b) the presence of any virus, worm or similar malicious or disabling
> code in, this message or any attachment(s) to it. If verification of this
> email is sought then please request a hard copy. Unless otherwise stated
> this email: (1) is not, and should not be treated or relied upon as,
> investment research; (2) contains views or opinions that are solely those of
> the author and do not necessarily represent those of NIplc; (3) is intended
> for informational purposes only and is not a recommendation, solicitation or
> offer to buy or sell securities or related financial instruments.  NIplc
> does not provide investment services to private customers.  Authorised and
> regulated by the Financial Services Authority.  Registered in England
> no. 1550505 VAT No. 447 2492 35.  Registered Office: 1 St Martin's-le-Grand,
> London, EC1A 4NP.  A member of the Nomura group of companies.
> 
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Joda-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
> 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to