elm-community / elm-time

A pure Elm date and time library.

Home Page:http://package.elm-lang.org/packages/elm-community/elm-time/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: Beginning of day in timezone

sporto opened this issue · comments

It would be great that elm-time could give me the beginning of a day in a particular timezone

This is what I'm doing now. based on a reference time and an offset

beginningOfDay : Int -> Time -> DT.DateTime
beginningOfDay offset referenceTime =
    referenceTime
        |> DT.fromTimestamp
        |> DT.addMilliseconds -offset
        |> DT.setHour 0
        |> DT.setMinute 0
        |> DT.setSecond 0
        |> DT.addMilliseconds offset

I've added a number of functions to ZonedDateTime in 1.4.0 that should make this kinda stuff easier. You should now be able to do:

beginningOfDay : TimeZone -> Time -> ZD.ZonedDateTime
beginningOfDay timeZone time =
  ZD.fromTimestamp timeZone time
    |> ZD.setHour 0
    |> ZD.setMinute 0
    |> ZD.setSecond 0