Elm Exactly
Results / elm-time /

TimeIssue16CustomZoneEraOrderTest

Tags:elm19-bug

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail

Issue: elm/time#16

`customZone` only works when its eras are listed from latest to earliest.

<https://github.com/elm/time/issues/16>

The documentation says "Human times will be based on the nearest `start`". With the eras listed
earliest first, `[ { start = 0, offset = 60 }, { start = 1000, offset = 120 } ]`, a time at minute
2000 must use the nearest start (1000, offset +2h): minute 2000 is 09:20 UTC on the second day,
so 11:20 local. Elm 0.19.1 (elm/time 1.0.0) takes the first era that started before the time, offset +1h, giving 10:20.

Results

elm-0.19.1

failran in 45 ms
Missing pattern: earliest first: (11,20)
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
earliest first: (10,20)
latest first: (11,20)

elm-0.19.2

failran in 49 ms
Missing pattern: earliest first: (11,20)
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
earliest first: (10,20)
latest first: (11,20)

elm-0.19.3

failran in 46 ms
Missing pattern: earliest first: (11,20)
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
earliest first: (10,20)
latest first: (11,20)

lamdera-1.5.0

failran in 51 ms
Missing pattern: earliest first: (11,20)
--- output ---
earliest first: (10,20)
latest first: (11,20)

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-time/TimeIssue16CustomZoneEraOrderTest] in its title.

Source

The -- CHECK: lines give the expected output.

module TimeIssue16CustomZoneEraOrderTest exposing (main)
{-| `customZone` only works when its eras are listed from latest to earliest.
<https://github.com/elm/time/issues/16>
The documentation says "Human times will be based on the nearest `start`". With the eras listed
earliest first, `[ { start = 0, offset = 60 }, { start = 1000, offset = 120 } ]`, a time at minute
2000 must use the nearest start (1000, offset +2h): minute 2000 is 09:20 UTC on the second day,
so 11:20 local. Elm 0.19.1 (elm/time 1.0.0) takes the first era that started before the time, offset +1h, giving 10:20.
-}
-- TAGS: elm19-bug
-- CHECK: earliest first: (11,20)
-- CHECK: latest first: (11,20)
import Html exposing (text)
import Time
{-| Returns the local hour and minute in `zone` of the instant 2000 minutes after the epoch.
-}
hm : Time.Zone -> ( Int, Int )
hm zone =
let
t =
Time.millisToPosix (2000 * 60000)
in
( Time.toHour zone t, Time.toMinute zone t )
main =
let
_ =
Debug.log "earliest first" (hm (Time.customZone 0 [ { start = 0, offset = 60 }, { start = 1000, offset = 120 } ]))
_ =
Debug.log "latest first" (hm (Time.customZone 0 [ { start = 1000, offset = 120 }, { start = 0, offset = 60 } ]))
in
text "done"