summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2021-11-15 19:31:37 -0500
committerLinus Groh <mail@linusgroh.de>2021-11-16 00:41:45 +0000
commita164e6ecbbea4ee787d43cf083f4df352d758129 (patch)
tree24718091ddefa4da911b3ebdb0e45b44a728c9e8
parent8f8ae5eb53bfff1b4f0d15e0013cab41208b2bc8 (diff)
downloadserenity-a164e6ecbbea4ee787d43cf083f4df352d758129.zip
LibJS: Unbreak to_iso_day_of_week
481f7d6afa89d tried to use `modulo()` here, but missed that the code used `<=` instead of `<`. Keep using `modulo()` and add an explicit conditional, which is arguably clearer.
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
index 55c053fa66..93ddf1e22a 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
@@ -665,7 +665,10 @@ u8 to_iso_day_of_week(i32 year, u8 month, u8 day)
auto normalized_year = year - (month < 3 ? 1 : 0);
auto century = normalized_year / 100;
auto truncated_year = normalized_year - (century * 100);
- return modulo(day + static_cast<u8>((2.6 * normalized_month) - 0.2) - (2 * century) + truncated_year + (truncated_year / 4) + (century / 4), 7);
+ auto day_of_week = modulo(day + static_cast<u8>((2.6 * normalized_month) - 0.2) - (2 * century) + truncated_year + (truncated_year / 4) + (century / 4), 7);
+
+ // https://cs.uwaterloo.ca/~alopez-o/math-faq/node73.html computes day_of_week as 0 = Sunday, ..., 6 = Saturday, but for ToISODayOfWeek Monday is 1 and Sunday is 7.
+ return day_of_week == 0 ? 7 : day_of_week;
}
// 12.1.34 ToISODayOfYear ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisodayofyear