Dayjs output not correct
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
I have a big data set that gets narrowed down by the date the entity was createdAt,
```ts
const testFunc = pipe(
// masive dataset !!!
dataSet1,
ReadonlyArray.map((x) => {
const created = dayjs(x.createdAt) // for readability
return {
month: created.month() + 1, // Dayjs is 0 indexed
year: created.year(),
iso: created.toISOString(),
noFormat: x.createdAt, // date from server
}
}),
)
```
At this point my expected output is for month to 1-12 corresponding to the iso
instead it in some cases gives me the next month
Out put for Month 4 and first entry of 5
```
// Output 1
{
iso: '2023-04-09T21:54:06.000Z'
month: 4
noFormat: '2023-04-09T21:54:06.000Z' // from server
year: 2023
}
// Output 2
{
iso: '2023-04-09T21:54:06.000Z'
month: 4
noFormat: '2023-04-09T21:54:06.000Z' // from server
year: 2023
}
// Output 3
{
iso: '2023-04-23T22:00:26.000Z'
month: 4
noFormat: '2023-04-23T22:00:26.000Z' // from server
year: 2023
}
// Output 4
{
iso: "2023-04-30T22:29:20.000Z"
month: 5
noFormat: "2023-04-30T22:29:20.000Z" // from server
year: 2023
}
```
So for this specific entity I should be seeing entries 4 times in the 4th month (April),
instead there is 3 entries, this happens in many other parts as well
If there is other possible factors that could influence my output please let me know,
// Dates is serverside and different from my timezone // should not matter date comes from server and gets processed clientside
If anyone else has had this problem and know a work around , would want to use the dayjs lib for solution not alternative lib,
- Day.js Version 1.11.10
- Browser firefox, chrome-based
- Time zone: South African Standard Time GMT + 02:00
Contributor guide
Research direction
Start with the provided Day.js 1.11.10 mapping snippet and reproduce the April 30 case in the reported GMT+02:00 environment, comparing month(), year(), and toISOString() for the same input. Determine whether the discrepancy is reproducible and whether it reflects a library bug or differing local and UTC interpretations; document the result and any required Day.js behavior change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100