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

[Bug] This library does not handle leap seconds #30

Open
ad-si opened this issue Feb 5, 2021 · 0 comments
Open

[Bug] This library does not handle leap seconds #30

ad-si opened this issue Feb 5, 2021 · 0 comments

Comments

@ad-si
Copy link

ad-si commented Feb 5, 2021

This library does not handle leap seconds, and is based on an incorrect understanding of Unix time.
Therefore I think it's not usable as the core time library for Elm.

With POSIX time, it does not matter where you live or what time of year it is. It is just the number of seconds elapsed since some arbitrary moment (in 1970).

  • It does matter what time of year it is, because during a leap second a Unix timestamp exists twice
  • Seconds elapsed since some arbitrary moment minus leap seconds

So to show a human being a time, you must always know the POSIX time and their time zone.

and wether you're currently experiencing a leap second or note

Point is, the only thing ISO 8601 is good for is representing a Time.Posix, but less memory efficient and more confusing.

Incorrect. It's impossible to specify the moment 1998-12-31T23:59:60.5 with posix time, although that moment existed.
So currently there is a timeframe of 27 seconds since 1970 which can not be specified with this library, and this number will increase in the future. I think this is not acceptable for a core time library.

So I recommend using Time.posixToMillis and Time.millisToPosix for any client/server communication you control.

I'd recommend to never use the unix time for any communication due to aforementioned ambiguities.

The default time data type should probably rather be something like this:

type alias Moment =
    { year : Int
    , month : Month
    , day : Int
    , hour : Int
    , minute : Int
    , second : Int
    , millisecond : Int
    }

or

type Moment = Moment String
// e.g. Moment "1998-12-31T23:59:60.5"

(Moment is the nomenclature used in the ISO 8601 specification, and is better suited than Time in my opinion)

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

1 participant