formatUTCWeekNumberISO and formatWeekNumberISO return incorrect results at edge of the year

Open
#120 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
backend

Research direction

The issue identifies formatUTCWeekNumberISO and formatWeekNumberISO in d3-time-format and provides a CodePen reproduction. Read those functions and the related tests, then check the reported year-boundary case; done means both functions return the correct ISO week number at the edge of the year.

Written by the indexing model from the issue text.

Description

These functions work by counting how many Thursdays have occurred up to this date

function formatUTCWeekNumberISO(d, p) { d = UTCdISO(d); return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2); }

Unfortunately the argument d is re-assigned and can cause the year to roll over, so that utcYear(d) returns a different year because UTC is in a different timezone

Codepen: https://codepen.io/28raining/pen/VwqYaKL?editors=1111

Using a separate variable avoids this

function formatUTCWeekNumberISO(d, p) { var dUTC = UTCdISO(d); return pad(utcThursday.count(utcYear(d), dUTC ) + (utcYear(d).getUTCDay() === 4), p, 2); }

Dominant language
JavaScript
Stars
338
Forks
100
Avg merge
6h 20m
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from d3/d3-time-format

All issues in d3/d3-time-format

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.