Skip to content

CFDate: return the ISO 8601 week of the year - #128

Open
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/cfdate-weekofyear
Open

CFDate: return the ISO 8601 week of the year#128
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/cfdate-weekofyear

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

CFAbsoluteTimeGetWeekOfYear computed the week as d / 7 % 52. That ignores which day of the week the year starts on and can never return week 53, so almost every date came back with the wrong week (for example 2004-12-31 gave 0 instead of 53).

Compute the ISO 8601 week number instead: weeks start on Monday and week 1 is the week containing the year's first Thursday, so days at the start or end of a year can belong to a week of the adjacent year. A helper returns whether a year has 52 or 53 ISO weeks.

Tests/CFDate/weekofyear.m covers the first weeks of the year, the mid-January boundaries, and the year-end rollovers for both a 52-week and a 53-week year, verified against Apple CoreFoundation.

CFAbsoluteTimeGetWeekOfYear returned d / 7 % 52, which ignored the day of the
week and could never reach week 53.  Compute the ISO 8601 week number, where
weeks start on Monday and week 1 contains the year first Thursday, so days
near a year boundary fall in a week of the adjacent year.
@DTW-Thalion
DTW-Thalion force-pushed the fix/cfdate-weekofyear branch from 7b02f4b to 36c3358 Compare July 24, 2026 15:22
@DTW-Thalion DTW-Thalion reopened this Jul 24, 2026
@DTW-Thalion DTW-Thalion reopened this Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant