iamkun / iamkun/dayjs

isoWeek() returns wrong value

Open
#2,187 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
.isoWeek(week) should set proper week

**Expected behavior**
.isoWeek(week) sets week from previous year instead

**Information**
- Day.js Version v1.11.7
- OS: Windows
- Browser: Chrome 108
- Time zone: GMT +1

Reproduction code:

```
const dayjs = require("dayjs");
var isoWeek = require('dayjs/plugin/isoWeek')
dayjs.extend(isoWeek);

year = 2021;
week = 51;

date = dayjs();
date2021 = dayjs().year(year);
date2021week51 = dayjs().year(year).isoWeek(week);

console.log(date); // correct
console.log(date2021); // correct
console.log(date2021week51); // incorrect - should be week 51 of year 2021, not 2020
```

https://runkit.com/63b3f5320465cd00088b7bd9/63b3f5e70465cd00088b7c55

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction code and the dayjs/plugin/isoWeek entry point, using the 2021/week 51 case to trace how the target year is selected. Confirm the behavior against ISO week-year rules and add or update a regression test so isoWeek(51) resolves to week 51 of 2021 rather than 2020.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.