How to add 1 day to a Posix in 0.19


#1

I am upgrading from 0.18 to 0.19.

I previously had code like
add Day -1 from

now that from is a Posix, how do I replicate that functionality?


#2

Something like this will add 24 hours

posix
    |> Time.posixToMillis
    |> (+) (24 * hour)
    |> Time.millisToPosix

hour =
1000 * 60 * 60

But this doesn’t account for any daylight savings time changes, which might not be what you want.


#3

I’ve been using the Time.Extra package by Justin Mimbs which works with Posix in 0.19:

https://package.elm-lang.org/packages/justinmimbs/time-extra/1.0.1/Time-Extra

e.g:

posix |> add Day -1 Time.utc

#4

Thanks - are you happy with that package?


#5

Yes, I’m happy with it; I haven’t come across any issues thus far - but I’m not doing anything particularly strenuous either (I’m not dealing with multiple time-zones).

The author is active and also has a package for time-zones (justinmimbs/timezone-data) with the in-built IANA time-zone database. He also has a date-extra package for 0.18.