Issue with leap year?

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

Issue with leap year?

Dan Washusen
Hey all,
We're seeing some very odd behaviour and I think it's to do with the leap year.  The code in question is:

Instant someDate = new Instant(1329847846391); // 2012-03-21T18:10:46.391Z
if (someDate.isAfterNow()) {
throw new IllegalStateException()
}

The systems current date is: Thu Mar  1 21:06:59 UTC 2012

Obviously the 21st of March 2012 is well after the 1st of march but it passes the check and goes through (charging a credit card)… Any ideas?  My guess is that it's something to do with the leap year…?

Cheers,
Dan

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
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: Issue with leap year?

Dan Washusen
OK, so the 1329847846391 is actually 2012-02-21 so the check below is working as expected.  The issue was actually caused by the following:
DateTime paymentNext = new DateTime(billingAccount.getPaymentNext()).plus(Months.ONE);

When that happened the we logged out:
Next payment will be 2012-03-21T18:10:46.391Z

But the value written to the DB was: 1329847846391

Hmmm
-- 
Dan Washusen
Make big files fly

On Friday, 2 March 2012 at 9:25 AM, Dan Washusen wrote:

Hey all,
We're seeing some very odd behaviour and I think it's to do with the leap year.  The code in question is:

Instant someDate = new Instant(1329847846391); // 2012-03-21T18:10:46.391Z
if (someDate.isAfterNow()) {
throw new IllegalStateException()
}

The systems current date is: Thu Mar  1 21:06:59 UTC 2012

Obviously the 21st of March 2012 is well after the 1st of march but it passes the check and goes through (charging a credit card)… Any ideas?  My guess is that it's something to do with the leap year…?

Cheers,
Dan


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
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: Issue with leap year?

Mark Carroll
On 03/01/2012 06:02 PM, Dan Washusen wrote:
> But the value written to the DB was: 1329847846391

How are you mapping DateTimes to database values? For instance, with
org.jadira.usertype.dateandtime.joda.PersistentDateTime?

Mark

--
Mark Carroll
Software Engineer
[hidden email]
http://www.vecna.com/

Cambridge Research Laboratory
Vecna Medical
36 Cambridge Park Drive
Cambridge, MA 02140
Phone: (617) 864-0636
Fax: (617) 864-0638

Better Technology, Better World (TM)

The contents of this message may be privileged and confidential.
Therefore, if this message has been received in error, please delete it
without reading it. Your receipt of this message is not intended to
waive any applicable privilege. Please do not disseminate this message
without the permission of the author.

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
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: Issue with leap year?

Dan Washusen
Thanks for the response.  

We're using org.joda.time.contrib.hibernate.PersistentInstantAsBigInt to persist the Instant.  I'm pretty sure that's working correctly - we have extensive tests around the billing functionality and I've since written excruciatingly thorough tests using the same data as the production issue and it passes.

I'm wondering if there may have been an issue with the leap year and date math, it's a long shot but it's all I can think of.  The following  (roughly) was executed on the 2012-03-01 20:06...

Instant lastPayment = new Instant(1329847846391); // 2012-02-21T18:10:46.391Z
DateTime paymentNext = new DateTime(lastPayment, DateTimeZone.UTC).plus(Months.ONE);

The paymentNext was then logged out (slf4j) as 2012-03-21T18:10:46.391Z before being written to the DB (hibernate, no errors). However, the value in the DB didn't have the new date…

I've tried rolling back the system date on my Mac and running the same and it all works.  In production it runs on Ubuntu Server 11.10, Oracle Java 1.6.0_26, Joda 2.0… 


On Saturday, 3 March 2012 at 12:49 AM, Mark Carroll wrote:
On 03/01/2012 06:02 PM, Dan Washusen wrote:
But the value written to the DB was: 1329847846391

How are you mapping DateTimes to database values? For instance, with
org.jadira.usertype.dateandtime.joda.PersistentDateTime?

Mark

--
Mark Carroll
Software Engineer

Cambridge Research Laboratory
Vecna Medical
36 Cambridge Park Drive
Cambridge, MA 02140
Phone: (617) 864-0636
Fax: (617) 864-0638

Better Technology, Better World (TM)

The contents of this message may be privileged and confidential.
Therefore, if this message has been received in error, please delete it
without reading it. Your receipt of this message is not intended to
waive any applicable privilege. Please do not disseminate this message
without the permission of the author.

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
_______________________________________________
Joda-interest mailing list


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
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: Issue with leap year?

jodastephen
Not sure what to suggest myself. I'm not aware of any issues like you've seen
Stephen

On 2 March 2012 20:19, Dan Washusen <[hidden email]> wrote:

> Thanks for the response.
>
> We're using org.joda.time.contrib.hibernate.PersistentInstantAsBigInt to
> persist the Instant.  I'm pretty sure that's working correctly - we have
> extensive tests around the billing functionality and I've since written
> excruciatingly thorough tests using the same data as the production issue
> and it passes.
>
> I'm wondering if there may have been an issue with the leap year and date
> math, it's a long shot but it's all I can think of.  The following
>  (roughly) was executed on the 2012-03-01 20:06...
>
> Instant lastPayment = new Instant(1329847846391); //
> 2012-02-21T18:10:46.391Z
> DateTime paymentNext = new DateTime(lastPayment,
> DateTimeZone.UTC).plus(Months.ONE);
>
> The paymentNext was then logged out (slf4j) as 2012-03-21T18:10:46.391Z
> before being written to the DB (hibernate, no errors). However, the value in
> the DB didn't have the new date…
>
> I've tried rolling back the system date on my Mac and running the same and
> it all works.  In production it runs on Ubuntu Server 11.10, Oracle
> Java 1.6.0_26, Joda 2.0…
>
>
> On Saturday, 3 March 2012 at 12:49 AM, Mark Carroll wrote:
>
> On 03/01/2012 06:02 PM, Dan Washusen wrote:
>
> But the value written to the DB was: 1329847846391
>
>
> How are you mapping DateTimes to database values? For instance, with
> org.jadira.usertype.dateandtime.joda.PersistentDateTime?
>
> Mark
>
> --
> Mark Carroll
> Software Engineer
> [hidden email]
> http://www.vecna.com/
>
> Cambridge Research Laboratory
> Vecna Medical
> 36 Cambridge Park Drive
> Cambridge, MA 02140
> Phone: (617) 864-0636
> Fax: (617) 864-0638
>
> Better Technology, Better World (TM)
>
> The contents of this message may be privileged and confidential.
> Therefore, if this message has been received in error, please delete it
> without reading it. Your receipt of this message is not intended to
> waive any applicable privilege. Please do not disseminate this message
> without the permission of the author.
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...