Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last day of month/year bug in epochMillisToDateTimeHelp function #25

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ done

$roc test platform/Url.roc

$roc test platform/InternalDateTime.roc

# test building website
$roc docs platform/main.roc
15 changes: 13 additions & 2 deletions platform/InternalDateTime.roc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ epochMillisToDateTimeHelp = \current ->
countDaysInYear = if isLeapYear current.year then 366 else 365
countDaysInMonth = daysInMonth current.year current.month

if current.day >= countDaysInYear then
if current.day > countDaysInYear then
epochMillisToDateTimeHelp {
year: current.year + 1,
month: current.month,
Expand All @@ -126,7 +126,7 @@ epochMillisToDateTimeHelp = \current ->
minutes: current.minutes - (countDaysInYear * 24 * 60),
seconds: current.seconds - (countDaysInYear * 24 * 60 * 60),
}
else if current.day >= countDaysInMonth then
else if current.day > countDaysInMonth then
epochMillisToDateTimeHelp {
year: current.year,
month: current.month + 1,
Expand All @@ -142,6 +142,17 @@ epochMillisToDateTimeHelp = \current ->
seconds: current.seconds % 60,
}


# test last day of 1st year after epoch
expect
str = (364 * 24 * 60 * 60 * 1000) |> epochMillisToDateTime |> toIso8601Str
str == "1970-12-31T00:00.00Z"

# test last day of 1st month after epoch
expect
str = (30 * 24 * 60 * 60 * 1000) |> epochMillisToDateTime |> toIso8601Str
str == "1970-01-31T00:00.00Z"

# test 1_700_005_179_053 ms past epoch
expect
str = 1_700_005_179_053 |> epochMillisToDateTime |> toIso8601Str
Expand Down
Loading