time icon indicating copy to clipboard operation
time copied to clipboard

Add a `Time.secondsToPosix`

Open Qqwy opened this issue 6 years ago • 1 comments

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.

Qqwy avatar Nov 25 '18 15:11 Qqwy

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.

malaire avatar Apr 14 '20 21:04 malaire