roc-lang / basic-webserver

A basic webserver in Roc

Home Page:https://roc-lang.github.io/basic-webserver/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InternalDateTime `epochMillisToDateTime` produces a Integer overflow error

RMailaender opened this issue · comments

I discovered a bug in my own code, which was heavily influenced by epochMillisToDateTime (a.k.a I copy pasted it as a wip).
Adding this expect to InternalDateTime let's it crash:

# 2023-12-31 18:00:00
expect
    str =
        1_704_045_600_000
        |> epochMillisToDateTime
        |> toIso8601Str

    str == "2023-12-31T18:00.00Z"
> roc test ./platform/InternalDateTime.roc
── EXPECT PANICKED in ./platform/InternalDateTime.roc ──────────────────────────

This expectation crashed while running:

145│>  # 2023-12-31 18:00:00
146│>  expect
147│>      str =
148│>          1704045600_000
149│>          |> epochMillisToDateTime
150│>          |> toIso8601Str
151│>
152│>      str == "2023-12-31T18:00.00Z"

The crash reported this message:

Integer multiplication overflowed!

1 failed and 24 passed in 535 ms.

it seems that the error occurs here:

    if current.day >= countDaysInYear then
        epochMillisToDateTimeHelp {
            year: current.year + 1,
            month: current.month,
            day: current.day - countDaysInYear,
            # at some point current.hours = 8755
            # while (countDaysInYear * 24) = 8760
            # so:  current.hours - (countDaysInYear * 24) == -5
            hours: current.hours - (countDaysInYear * 24),
            minutes: current.minutes - (countDaysInYear * 24 * 60),
            seconds: current.seconds - (countDaysInYear * 24 * 60 * 60),
        }

When I find the time to fix it, I'll create a MR.

this should be closed with #25