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

Add a Time.secondsToPosix #11

Open
Qqwy opened this issue Nov 25, 2018 · 1 comment
Open

Add a Time.secondsToPosix #11

Qqwy opened this issue Nov 25, 2018 · 1 comment

Comments

@Qqwy
Copy link

Qqwy commented Nov 25, 2018

Currently, there only is a Time.millisToPosix. This means that when for instance a server-side application exposes a timestamp already in POSIX format, that the only way to convert them to an Elm Time.Posix value is to do some roundabout trickery like:

JD.int |> JD.map (\posix_seconds -> posix_seconds * 1000 |> Time.millisToPosix)

(So first we multiply the number of seconds by 1000 to become a number in milliseconds first). I think it would make sense, because 'POSIX time' is only specified as being counted in full seconds, and because (probably second to the ISO8601 format that this library purposefully rejects) it is the most common format that is exposed by server languages.

@malaire
Copy link

malaire commented Apr 14, 2020

Your example can be shortened to

JD.int |> JD.map ((*) 1000 >> Time.millisToPosix)

and I think that this is clear/short enough that Time.secondsToPosix isn't essential to have, but would be a nice addition.

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

2 participants