3 Replies Latest reply on Jun 13, 2012 1:28 PM by Ned Murphy

# Date() - Buggy behaviour working with Number() or uint()

It took me half day to track down this, apparently it is a bug (I don't know if there is some obscure logic behind it).

Date() behaves much differently when casted/created with the same amount as Number() or uint()

Here is the output when tracing:

 new Date() = Wed Jun 13 20:12:43 GMT+0200 2012 new Date().time = 1339611163266 Number(new Date()) = 1339611163266 uint(new Date()) = 3876334210 new Date(Number(1339610984911)) = Wed Jun 13 20:09:44 GMT+0200 2012 new Date(uint(1339610984911)) = Sat Feb 14 21:42:35 GMT+0100 1970

As you can see, converting a date to Number(new Date()) or uint(new Date()) gives a completely different result.

Also, working with the same time amount, if new Date(Number(time)) or new Date(uint(time)) returns a completely different date.

So, even though milliseconds from 1st jan 1970 are obviously an integer, AS3 treats it differently if casted to Number or uint.

Is there a logic? To me it looks like a bug...

namaste

Filippo

• ###### 1. Re: Date() - Buggy behaviour working with Number() or uint()

It is not likely to be a bug... chances are very few things that people feel are bugs are.  The maximum value for a uint number is 4294967295, which is well under the value for the Date's time value you are getting.  So it is likely throwing out some remainder value after trying to cope with such a large value.

• ###### 2. Re: Date() - Buggy behaviour working with Number() or uint()

Allright there's a logic then

thanks

So, is uint limited compared to Number?

Thanks for the info, I never thought that... I need to rethink about some values I always type to uint

• ###### 3. Re: Date() - Buggy behaviour working with Number() or uint()

If you look up the different numeric classes you will see how they differ in their limits.  One problem you will probably run into someday ( I have a couple times) is when you use a uint as a counter in a loop that is counting backwards... when it should reach a -1, which it cannot do, it jumps to 4294967295, leaving you scratching your head wondering why the loop never ended or some other out of range error occurs.