Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time.Posix has insufficient range #27

Open
ksvanhorn opened this issue May 28, 2020 · 4 comments
Open

Time.Posix has insufficient range #27

ksvanhorn opened this issue May 28, 2020 · 4 comments

Comments

@ksvanhorn
Copy link

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.

@rlefevre
Copy link
Member

rlefevre commented May 28, 2020

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.

@ksvanhorn
Copy link
Author

"some operations"?

@rlefevre
Copy link
Member

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.

@malaire
Copy link

malaire commented Oct 26, 2020

"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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants