Skip to content

Commit

Permalink
Merge pull request #25 from imclerran/main
Browse files Browse the repository at this point in the history
Fix last day of month/year bug in epochMillisToDateTimeHelp function
  • Loading branch information
Anton-4 authored Jan 30, 2024
2 parents 2c4d98b + 205b977 commit a91f54c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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

0 comments on commit a91f54c

Please sign in to comment.