Skip to content

fix: correct week calculation when date is before year start week - #2988

Open
James-4u wants to merge 1 commit into
iamkun:devfrom
James-4u:fix/week-calculation-bug-2987
Open

fix: correct week calculation when date is before year start week#2988
James-4u wants to merge 1 commit into
iamkun:devfrom
James-4u:fix/week-calculation-bug-2987

Conversation

@James-4u

@James-4u James-4u commented Jan 5, 2026

Copy link
Copy Markdown

Closes #2987

When subtracting one week from January 4, 2026, the week number was incorrectly calculated as week 1 of 2025 instead of the correct week (52 or 53 depending on locale).

The issue was in the recursive call when diffInWeek < 0. This fix replaces the recursive call with proper calculation based on the previous year's year start.

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=102175066

 iamkun#2987)

When subtracting one week from January 4, 2026, the week number was
incorrectly calculated as week 1 of 2025 instead of the correct week
(52 or 53 depending on locale).

The issue was in the recursive call when diffInWeek < 0. This fix
replaces the recursive call with proper calculation based on the
previous year's year start.

- Fix week calculation for dates before year start week
- Add test cases for issue iamkun#2987
@James-4u

James-4u commented Jan 5, 2026

Copy link
Copy Markdown
Author

requesting your reviews @iamkun
cc: @datastructurey

@datastructurey

Copy link
Copy Markdown

@SmartDever02 @iamkun I modified and submitted a PR based on my understanding; you can take a look. #2990
I'm a newbie and not very familiar with the contribution rules, sorry.

@James-4u

Copy link
Copy Markdown
Author

are you open to contribution or not? please let me know @iamkun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The week number obtained after subtracting one week from January 4, 2026 is incorrect.

2 participants