Jim White | 10 May 03:18

Re: [groovy-user] Problem with Date()

tog wrote:

> In groovysh:
> d   = new Date()
> d1 = new Date(d.time + 30*24*60*60*1000) brings me back to the future !!!
> 
> Looks like a bug ?

It may be a bug but not with Date.

30*24*60*60*1000
==>
-1702967296

I thought we got numeric promotion in Groovy but obviously not.

You can avoid the overflow by specifying a bigger type:

30*24*60*60*1000L
==>
2592000000

30*24*60*60*1000.0
==>
2592000000.0

But that won't help because you can't add a number bigger than Integer 
to a Date:

new Date() + 30*24*60*60*1000L
==>
groovy.lang.MissingMethodException: No signature of method: 
java.util.Date.plus() is applicable for argument types: (java.lang.Long) 
values: {2592000000}

Jim
---
Wings - Why take the train when you can fly?
http://IFCX.org

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane