views:

43

answers:

2

This is strange:

DateList@AbsoluteTime[596523]

returns

{2078, 7, 2, 2, 42, 9.7849}

But

DateList@AbsoluteTime[596524]

returns

{1942, 5, 26, 20, 28, 39.5596}

The question: What's going on? Note that AbsoluteTime with a numeric argument is undocumented.

(I think I now know what it's doing but figured this is useful to have as a StackOverflow question for future reference; and I'm curious if there's some reason for that magic 596523 number.)

PS: I encountered this when writing these utility functions for converting to and from unix time in Mathematica:

(* Using Unix time (an integer) instead of Mathematica's AbsoluteTime...      *)
tm[x___] := AbsoluteTime[x]            (* tm is an alias for AbsoluteTime.    *)
uepoch = tm[{1970}, TimeZone->0];      (* unixtm works analogously to tm.     *)
unixtm[x___] := Round[tm[x]-uepoch]    (* tm & unixtm convert between unix &  *)
unixtm[x_?NumericQ] := Round[x-uepoch] (*  mma epoch time when given numeric  *)
tm[t_?NumericQ] := t+uepoch            (*  args. Ie, they're inverses.        *)
+1  A: 

Calling AbsoluteTime[x] where x is an integer is an (undocumented) shortcut for AbsoluteTime[TimeZone->x]. Normal values for x then would be -12 to +12 but it happily adds or subtracts from UTC all the way up to half a million if you tell it to. Why it suddenly freaks out at 596,524 I don't know. But I guess one reasonable answer is "just don't do that!".

PS: The other answer reveals the mystery of the magic 596,524 hours. It's (2^31-1)/3600, ie, the biggest number of seconds you can store in an unsigned 32-bit integer.

dreeves
+4  A: 

If you convert 596524 and 596523 from hours to seconds (multiply by 3600) you'll see that the larger number is greater than 2^31-1 (the maximum 32-bit signed integer value) while the smaller number is not.

ragfield