time
time copied to clipboard
Time.Posix has insufficient range
Time.Posix is defined as
type Posix = Posix Int
where the integer field is in milliseconds since Jan. 1, 1970. However, the language documentation for Int states that
"Int math is well-defined in the range -2^31 to 2^31 - 1. Outside of that range, the behavior is determined by the compilation target."
This means that Posix time is only guaranteed to be able to represent times between 07 Dec 1969 03:28:37 UTC and 25 Jan 1970 20:31:22 UTC.
The documentation then says:
When generating JavaScript, the safe range expands to -2^53 to 2^53 - 1 for some operations
As Javascript is the only target for now, and the operations used for Posix.Time
are safe in this range, time should be safe from Sunday, September 26, -0885 2:04:12.591 AM to Sunday, April 7, 4824 9:55:47.409 PM.
But you're right that some care must be taken if a new target like WebAssembly is one day supported.
"some operations"?
Operations that only work in 32bit are bitwise operations: https://package.elm-lang.org/packages/elm/core/latest/Bitwise
Plus a few others that use them indirectly.
"some operations"
That is not documented anywhere - Elm is notoriously awfully documented. For example integer division will only work for 32-bit values so if you try to calculate average of two timestamps that will not work.
Also since "some operations" is not defined, list of those operations can change at any time. So e.g. addition could suddenly stop working.