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

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

Open
arzatskis opened this issue Dec 20, 2024 · 1 comment
Open
Labels
bug Something isn't working needs investigation

Comments

@arzatskis
Copy link

arzatskis commented Dec 20, 2024

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

@LFDanLu LFDanLu added the bug Something isn't working label Dec 20, 2024
@LFDanLu
Copy link
Member

LFDanLu commented Dec 20, 2024

Reproduced locally, looks to be the regex associated with zonedDates. I'm not sure the offset is actually incorrect because before 1884, the offset for Los Angeles was actually -7:52:58 in 1883 according to the tz database:

Zone America/Los_Angeles -7:52:58 -	LMT	1883 Nov 18 20:00u

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs investigation
Projects
Status: 🩺 To Triage
Development

No branches or pull requests

2 participants