LocalDate.fromCalendarFields does not check Calendar.ERA

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

LocalDate.fromCalendarFields does not check Calendar.ERA

Thorvald Natvig
Hi,

Due to a really wrong date ending up in our system, I found a small
discrepancy in LocalDate.fromCalendarFields.

calendar.get(Calendar.YEAR) will return +3 for both 3 AD and 3 BC, which
means they are both treated equally by fromCalendarFields.

I added a local workaround, which was simply:

        return new LocalDate(
                calendar.get(Calendar.YEAR) *
(calendar.get(Calendar.ERA) == GregorianCalendar.AD ? 1 : -1),
                calendar.get(Calendar.MONTH) + 1,
                calendar.get(Calendar.DAY_OF_MONTH));

.. which seems to have fixed the problem for me.

Any chance of this being fixed in the next release?

Regards,
Thorvald


------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: LocalDate.fromCalendarFields does not check Calendar.ERA

jodastephen
On 20 November 2012 21:53, Thorvald Natvig <[hidden email]> wrote:

> Due to a really wrong date ending up in our system, I found a small
> discrepancy in LocalDate.fromCalendarFields.
>
> calendar.get(Calendar.YEAR) will return +3 for both 3 AD and 3 BC, which
> means they are both treated equally by fromCalendarFields.
>
> I added a local workaround, which was simply:
>
>         return new LocalDate(
>                 calendar.get(Calendar.YEAR) *
> (calendar.get(Calendar.ERA) == GregorianCalendar.AD ? 1 : -1),
>                 calendar.get(Calendar.MONTH) + 1,
>                 calendar.get(Calendar.DAY_OF_MONTH));
>
> .. which seems to have fixed the problem for me.
>
> Any chance of this being fixed in the next release?

Bad coding on my part. Sorry. A GitHub pull request would pretty much
guarantee it being in the next release.
thanks
Stephen

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: LocalDate.fromCalendarFields does not check Calendar.ERA

jodastephen
Fixed, although you had an off-by-one error in your fix ;-)
Stephen

On 20 November 2012 22:38, Stephen Colebourne <[hidden email]> wrote:

> On 20 November 2012 21:53, Thorvald Natvig <[hidden email]> wrote:
>> Due to a really wrong date ending up in our system, I found a small
>> discrepancy in LocalDate.fromCalendarFields.
>>
>> calendar.get(Calendar.YEAR) will return +3 for both 3 AD and 3 BC, which
>> means they are both treated equally by fromCalendarFields.
>>
>> I added a local workaround, which was simply:
>>
>>         return new LocalDate(
>>                 calendar.get(Calendar.YEAR) *
>> (calendar.get(Calendar.ERA) == GregorianCalendar.AD ? 1 : -1),
>>                 calendar.get(Calendar.MONTH) + 1,
>>                 calendar.get(Calendar.DAY_OF_MONTH));
>>
>> .. which seems to have fixed the problem for me.
>>
>> Any chance of this being fixed in the next release?
>
> Bad coding on my part. Sorry. A GitHub pull request would pretty much
> guarantee it being in the next release.
> thanks
> Stephen

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...