Skip to content

Commit

Permalink
feat: toStandardZone with workaround
Browse files Browse the repository at this point in the history
Note that we subtract 1 minute from starting point of each era as a workaround before
elm/time#7 is fixed.
  • Loading branch information
pd9333 committed Jul 22, 2022
1 parent d9beaba commit de850c2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Time2.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Time2 exposing
, decoderOfZone
, encodeZone
, epoch
, toStandardZone
, utc
)

Expand Down Expand Up @@ -39,6 +40,31 @@ customZone name eras offsetOfEarliestEra =
}


{-|
import Time
start : Int
start =
61
zone : Time.Zone
zone =
customZone "" [ { start = start, offset = 120 } ] 0
|> toStandardZone
Time.millisToPosix (start * 60 * 1000)
|> Time.toHour zone
--> 3 -- This will be 1 once https://github.com/elm/time/issues/7 is fixed, we then need to fix our implementation
-}
toStandardZone : Zone -> Time.Zone
toStandardZone (Zone { eras, offsetOfEarliestEra }) =
eras
|> List.map (\{ start, offset } -> Era (start - 1) offset)
|> Time.customZone offsetOfEarliestEra


{-| Both `start` and `offset` of an era are minutes from `epoch`.
-}
type alias Era =
Expand Down

0 comments on commit de850c2

Please sign in to comment.