mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibWeb: Implement week_number_of_the_last_day
This commit is contained in:
parent
6b79508c08
commit
a72636ad8d
Notes:
sideshowbarker
2024-07-18 08:59:31 +09:00
Author: https://github.com/stelar7 Commit: https://github.com/SerenityOS/serenity/commit/a72636ad8d Pull-request: https://github.com/SerenityOS/serenity/pull/22244 Reviewed-by: https://github.com/bplaat ✅
1 changed files with 12 additions and 2 deletions
|
@ -831,10 +831,20 @@ static bool is_valid_time_string(StringView value)
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#week-number-of-the-last-day
|
||||
static u32 week_number_of_the_last_day(u64)
|
||||
static u32 week_number_of_the_last_day(u64 year)
|
||||
{
|
||||
// FIXME: sometimes return 53 (!)
|
||||
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#weeks
|
||||
// NOTE: A year is considered to have 53 weeks if either of the following conditions are satisfied:
|
||||
// - January 1 of that year is a Thursday.
|
||||
// - January 1 of that year is a Wednesday and the year is divisible by 400, or divisible by 4, but not 100.
|
||||
|
||||
// Note: Gauss's algorithm for determining the day of the week with D = 1, and M = 0
|
||||
// https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Gauss's_algorithm
|
||||
u8 day_of_week = (1 + 5 * ((year - 1) % 4) + 4 * ((year - 1) % 100) + 6 * ((year - 1) % 400)) % 7;
|
||||
|
||||
if (day_of_week == 4 || (day_of_week == 3 && (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))))
|
||||
return 53;
|
||||
|
||||
return 52;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue