iamkun / iamkun/dayjs

startOf('isoWeek') not as expected

Open
#1,638 0 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

code:
dayjs.extend(isoWeek);
const result=dayjs('2021-01').startOf('isoWeek');
result:
2020-12-28

I look up the information,ISO 8601:
ISOweek define: The week of the first Thursday of the year;

so dayjs('2021-01').startOf('isoWeek') is. 2021-01-04。

I read dayjs code ,does not filter thursday。

**return "isoweek" === i.p(e) ? s ? this.date(this.date() - (this.isoWeekday() - 1)).startOf("day") : this.date(this.date() - 1 - (this.isoWeekday() - 1) + 7).endOf("day") : n.bind(this)(e, t)**

I think like this:
**return "isoweek" === i.p(e) ? s ? (this.isoWeekday() < 5 ?
this.date(this.date() - (this.isoWeekday() - 1)).startOf("day")
:this.date(this.date() - 1 - (this.isoWeekday() - 1) + 8).endOf("day"))
: this.date(this.date() - 1 - (this.isoWeekday() - 1) + 7).endOf("day") : n.bind(this)(e, t)**

Contributor guide

Open the contributing guide

Research direction

Reproduce the dayjs.extend(isoWeek) and startOf('isoWeek') example from the issue, then inspect the isoWeek plugin's startOf path and compare it with the ISO 8601 week definition. Confirm whether the observed date is incorrect and add or update regression coverage if needed.

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.