Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TZDate class toISOString() method not returning correct ISO format #15

Open
krema opened this issue Sep 26, 2024 · 3 comments
Open

TZDate class toISOString() method not returning correct ISO format #15

krema opened this issue Sep 26, 2024 · 3 comments

Comments

@krema
Copy link

krema commented Sep 26, 2024

The toISOString() method of the TZDate class is not returning the correct output. According to the ISO 8601 standard, the toISOString() method should return a string in the format YYYY-MM-DDTHH:mm:ss.sssZ, where the timezone is always UTC, denoted by the suffix Z.

See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString

Current Behavior: The method currently returns:

// 2023-05-12T12:00:00.000+02:00    
new TZDate(2023, 4, 12, 12, 0, 0, 'Europe/Berlin').toISOString()

Please note that the format is wrong

Expected Behavior: The method should return (I'm located in 'Europe/Berlin') :

// 2023-05-12T10:00:00.000Z
new Date(2023, 4, 12, 12, 0, 0).toISOString()

I'm using v1.1.1

@johnny-T
Copy link

Hi, I am running into this issue as well in version 1.1.2. Not only the toISOString() method, but also the toJSON() method formats the time not in UTC but in local TZ.

@janneh
Copy link

janneh commented Oct 3, 2024

Same here. Also expected it to follow the ISO 8601 standard and that this should hold:

test("toISOString", () => {
  const sg = new TZDate(2022, 2, 13, "Asia/Singapore")
  const ny = sg.withTimeZone("America/New_York")

  expect(
    sg.toISOString()
  ).toBe(
    ny.toISOString()
  )
})

but currently results in:

+ Expected: "2022-03-12T11:00:00.000-05:00"
- Received: "2022-03-13T00:00:00.000+08:00"

@ianawilson
Copy link

Same on tz 1.1.2 and date-fns 4.1.0. I'm working around this with formatISO(date, {in: tz("UTC")}) to force it to UTC format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants