`dayjs.week` returns wrong number.
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
I have this function :
```typescript
/**
* Get the week information for the current week in UTC
* @param week - The week date to get the information for. Must be in YYYY-MM-DD format.
* @throws Error if the date is not valid
*/
export function getWeekInformation(date?: string): WeekInformation {
// If a week is provided, validate
if (date !== undefined && !isValidDate(date)) {
throw new Error(`Invalid date: ${week}. Accepted format: YYYY-MM-DD`);
}
// Get this week's Monday 00:00:00 UTC
const thisWeekStart = dayjs(date).startOf('week').utc(false);
if (!thisWeekStart.isValid()) {
throw new Error('Invalid week');
}
// Get this week's Sunday 11:59:00 UTC
const thisWeekEnd = thisWeekStart.endOf('week');
return {
weekDate: thisWeekStart.format('YYYY-MM-DD'),
startDate: thisWeekStart,
endDate: thisWeekEnd,
year: thisWeekStart.year(),
weekNumber: thisWeekStart.week()
};
}
```
`weekNumber` is always increased by one. For instance:
```typescript
dayjs('2022-12-31').week() // returns 53
```
**Expected behavior**
There are 52 weeks in a year, the above-isolated snippet should return 52.
**Information**
- Day.js Version: v1.11.3
- OS: macOS
- Browser: Node v16.14
- Time zone: Western Europe
Contributor guide
Research direction
Reproduce the reported dayjs('2022-12-31').week() result and inspect the week() implementation and its existing tests; the report names no repository file or test. Confirm the intended week-numbering rules, including years with 53 weeks, and add coverage that demonstrates the corrected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100