Skip to content

Fix week 0 for early January dates - #4

Open
dyk1454683243-sudo wants to merge 1 commit into
datetime:masterfrom
dyk1454683243-sudo:cursor/fix-week-zero-january-673f
Open

dyk1454683243-sudo wants to merge 1 commit into
datetime:masterfrom
dyk1454683243-sudo:cursor/fix-week-zero-january-673f

Conversation

@dyk1454683243-sudo

Copy link
Copy Markdown

Fixes #3.

week() used Math.floor(days / 7), so any date in the first Sunday-start week of the year (a value in [0, 7)) returned "0". The reporter hit this on 3 January 2017.

This keeps the existing Sunday-start helper (from #1) and makes the result 1-indexed with floor + 1, matching this package’s simple API and other datetime helpers that treat month numbers as 1-based. It is not a switch to ISO 8601 week numbering.

Behavior

Date Before After
2017-01-01 (Sun) "0" "1"
2017-01-03 (Tue) "0" "1"
2017-01-08 (Sun) "1" "2"
2017-03-13 "10" "11"

Tests

Regression coverage uses fixed Date inputs, including 2017-01-03, January 1 when it is not Sunday, and a mid-year date so numbering stays consistent after week 1.

Math.floor(days / 7) yields 0 for dates in the first partial week
(for example 3 January 2017). Adding 1 keeps Sunday-start numbering
and matches this package's simple 1-based API.

Fixes datetime#3

Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
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.

Wrong week number. Today (3 January 2017) it emits week 0.

2 participants