dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

Dayjs output not correct

Open WayneFilmalter opened this issue 1 year ago • 3 comments

I have a big data set that gets narrowed down by the date the entity was createdAt,

    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

WayneFilmalter avatar Jan 22 '24 19:01 WayneFilmalter

It seems that time zone has an affect on it, is there a way to use it and ignore timezone correction ?

WayneFilmalter avatar Jan 22 '24 20:01 WayneFilmalter

https://day.js.org/docs/en/timezone/set-default-timezone to any +0 timezone. Usually it is "UTC" for +0 offset like Z in the ISO string, but I believe you can find something in the Intl.supportedValuesOf('timeZone') heap :)

buza-me avatar Feb 01 '24 03:02 buza-me

@buza-me , I detailed here that setting the default timezone doesn't work correctly.

IonelLupu avatar May 31 '24 07:05 IonelLupu