Skip to content

zonedDateTime.toString() returns invalid string when year is < 1884 #7539

@arzatskis

Description

@arzatskis

Provide a general summary of the issue here

.toString() returns datetime string which is not valid. Offset part is incorrect. It also displays incvalid timezone offset in DateInput field.

🤔 Expected Behavior?

.toString() should return valid string, that can be parsed back

const zoned = parseZonedDateTime("1883-11-07T00:45[America/Los_Angeles]")
const string = zoned.toString(); // => "1883-11-07T00:45:00-08:00[America/Los_Angeles]"
const parseBack = parseZonedDateTime(string) // => should work? now doesn't 

😯 Current Behavior

  1. Incorrect offset time is output
  2. Even if trying to proved "valid" string for this date, parseZonedDateTime throws error
const zoned = parseZonedDateTime("1883-11-07T00:45[America/Los_Angeles]")
/* 1 */
const string = zoned.toString(); // => "1883-11-07T00:45:00-07:52.96666666666667[America/Los_Angeles]"
/* 2 */
const parsedBack = parseZonedDateTime("1883-11-07T00:45:00-08:00[America/Los_Angeles]") // throws error

💁 Possible Solution

I think it's related to issue that was discussed here: #3924. My guess is that something similar needs to be done when getting(setting?) zoned date time offset.

🔦 Context

In app I'm working on <DateInput /> values are used as string and gets updated in onChange. User types in year (e.g. 2024) all good up to this point. But once backspace is pressed, year becomes 202 and things break.

🖥️ Steps to Reproduce

https://codesandbox.io/p/sandbox/zlvx8s

Version

"react-aria-components": "1.5.0" / "@internationalized/date": "3.6.0" (happens in previous version too)

What browsers are you seeing the problem on?

Safari

If other, please specify.

No response

What operating system are you using?

macOS 15.1.1 (24B91)

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    🩺 To Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions