rluiten / elm-date-extra

Elm Date Extra library add/subtract/diff/format etc dates
http://package.elm-lang.org/packages/rluiten/elm-date-extra/latest
BSD 3-Clause "New" or "Revised" License
75 stars 36 forks source link

2 failing tests to illustrate a problem with Duration.diff #62

Closed ikr closed 6 years ago

ikr commented 6 years ago

Case 1: 2019-01-01 — 2018-01-11T21:00:00

> subtrahend = moment.utc(1546300800000)
moment.utc("2019-01-01T00:00:00.000+00:00")
> minuend = moment.utc(1515704400000)
moment.utc("2018-01-11T21:00:00.000+00:00")
> minuend.add({months: 11, days: 20, hours: 3})
moment.utc("2019-01-01T00:00:00.000+00:00")

However, Duration.diff returns -1 month instead

↓ Duration.diff on directly created dates
✗ 2019-01-01 — 2018-01-11T21:00:00

    { year = 0, month = 11, day = 20, hour = 3, minute = 0, second = 0, millisecond = 0 }
    ╷
    │ Expect.equal
    ╵
    { year = 1, month = -1, day = 20, hour = 3, minute = 0, second = 0, millisecond = 0 }

Case 2: 2019-01-11 — 2018-01-11T21:00:00

> subtrahend = moment.utc(1547164800000)
moment.utc("2019-01-11T00:00:00.000+00:00")
> minuend = moment.utc(1515704400000)
moment.utc("2018-01-11T21:00:00.000+00:00")
> minuend.add({months: 11, days: 30, hours: 3})
moment.utc("2019-01-11T00:00:00.000+00:00")

However, Duration.diff returns -1 day instead

↓ Duration.diff on directly created dates
✗ 2019-01-11 — 2018-01-11T21:00:00

    { year = 0, month = 11, day = 30, hour = 3, minute = 0, second = 0, millisecond = 0 }
    ╷
    │ Expect.equal
    ╵
    { year = 1, month = 0, day = -1, hour = 3, minute = 0, second = 0, millisecond = 0 }
rluiten commented 6 years ago

Can you tell me your time zone not sure the problem is day light saving related but it might be. It does not look trivial to track down, so will have to allocate a few hours to look into properly in next few weeks.

ikr commented 6 years ago

I'm in Europe/Zurich

rluiten commented 6 years ago

Thanks have tests locally, its not your time zone specifically.

rluiten commented 6 years ago

I suspect you are not using Windows ;). Just found out elm still has the problem of parsing large integers correctly, due to its compiler and run time. I had to add ".0" to the 4 times you have in test to make them work for the dates you comment.

Note i am in Windows :).

ikr commented 6 years ago

Interestingly, the deltas are different in Ellie

https://ellie-app.com/79kkCgBXNa1/0

0 years 0 months 6 days 3 hours 0 years 0 months 16 days 3 hours

ikr commented 6 years ago

Ha! Right! If I add ".0" in Ellie, the deltas are the same as those I'm getting with elm-test in the terminal. I'm on Linux.

rluiten commented 6 years ago

Yes the problem i have without making sure they are parsed as floats by elm in windows. Reading large integers does weird things - there is a bug raised against compiler way back I believe its tied up with Haskell compiler.

rluiten commented 6 years ago

I had some inspiration and was awake anyway, I believe I have fixed the core problem. It was relatively simple even if I can't help but feel the diff code might be more succinct its quite wordy :). Published 9.2.3.

ikr commented 6 years ago

Hey, that's awesome! Thank you very much!