Parse week and year
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
We have a need to calculate week numbers backwards from a given week year, for example:
`week: 02, year: 2022` ->` [{week: 01, year: 2022}, {week: 53, year: 2022}]`
In order to do this, we are creating a dayjs object like this:
`dayjs().weekYear(year).week(week)` and then subtracting 1 week at a time.
However, we have found that doing it like this is prone to developer errors, as doing something like this:
`dayjs().week(week).weekYear(year)`
returns an incorrect date in some cases.
Therefore, we want to create the dayjs object already parsed in the correct moment in time, as shown in the [docs](https://day.js.org/docs/en/parse/string-format) for example.
However, this feature is unavailable if we want to set by year and week **only**.
**Expected behavior**
`dayjs('2022-53', 'YYYY-WW').format()`
returns
`2022-12-25`
``
**Information**
- Day.js Version [e.g. v1.11.2]
- OS: osx Monterey 12.5.1
- Browser Chrome 109.0.5414.87
- Time zone: [e.g. GMT+02:00 (Asia/Jerusalem)]
Contributor guide
Research direction
Start with the string-format parsing behavior described in the linked Day.js documentation and reproduce dayjs('2022-53', 'YYYY-WW'). Check how week and week-year values are currently parsed and tested. Done means the year-week input resolves to the expected date without depending on the order of weekYear() and week().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100