Skip to content

Implementation of toZonedDateTimeISO for Instant #258

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

Merged
merged 4 commits into from
Apr 8, 2025

Conversation

lockels
Copy link
Contributor

@lockels lockels commented Apr 2, 2025

Fixes #246

Implementation of toZonedDateTimeISO for Instant.

most tests pass, one strange test262 function looks like it should pass, but doesn't somehow.

https://github.com/tc39/test262/blob/main/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string-datetime.js

This one in particular.. The code does indeed throw a range error when trying to create a timezone from those strings.. but the test doesn't pass.

@lockels
Copy link
Contributor Author

lockels commented Apr 2, 2025

Huh.. strange that one of the tests fail here.. Passes locally, and that file is not touched by this PR

@nekevss
Copy link
Member

nekevss commented Apr 2, 2025

Huh, are you running on an ubuntu distro? Also, have you rebased to main for this PR?

@nekevss
Copy link
Member

nekevss commented Apr 2, 2025

most tests pass, one strange test262 function looks like it should pass, but doesn't somehow.

I think that should be consistent with some of the other methods then. There are some parsing bugs for time zones that should be fixed either when we update ixdtf or the work on time zone normalization is completed. See #251 and #257 if you're curious.

@@ -105,7 +105,8 @@ impl TimeZone {
}

pub fn try_from_str(src: &str) -> TemporalResult<Self> {
if let Ok(timezone) = Self::try_from_identifier_str(src) {
let normalized = src.to_uppercase();
Copy link
Member

@nekevss nekevss Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wait this is probably what's causing the failure.

So this is actually sort of a tricky case.

If you upper case a time zone string, "America/New_York" becomes "AMERICA/NEW_YORK". The file system will return no such file or directory because it's case sensitive (although, this may actually depend on your OS configuration). That's actually what #251 is working towards, providing a case insensitive way to return the normalized time zone strings (recommend taking a look at debug/iana_normalizer.json).

@lockels lockels force-pushed the instant_to_zdt_iso branch from 75577d7 to 2fc0cac Compare April 3, 2025 11:35
@lockels lockels marked this pull request as draft April 3, 2025 11:36
@lockels
Copy link
Contributor Author

lockels commented Apr 3, 2025

Huh, are you running on an ubuntu distro?

Nope, makes sense why it fails since i'm on a mac.

Also, have you rebased to main for this PR?

Nope, but i think i managed to fix that now.

I'll convert this PR to a draft for now..

@lockels lockels marked this pull request as ready for review April 8, 2025 15:04
@lockels lockels force-pushed the instant_to_zdt_iso branch from 6bbd835 to 2e3e513 Compare April 8, 2025 15:06
@@ -236,8 +236,12 @@ impl Instant {
}

// TODO: May end up needing a provider API during impl
pub fn to_zoned_date_time_iso(&self, _time_zone: TimeZone) -> TemporalResult<ZonedDateTime> {
Err(TemporalError::general("Not yet implemented"))
pub fn to_zoned_date_time_iso(&self, time_zone: TimeZone) -> TemporalResult<ZonedDateTime> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: I think this can be made non-fallible.

Calendar::from_utf8(b"iso8601") can be Calendar::default(), and then this method returns ZonedDateTime directly without a result.

This is inline with the specification:

8.3.15 Temporal.Instant.prototype.toZonedDateTimeISO ( timeZone )

This method performs the following steps when called:

    1. Let instant be the this value.
    2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
    3. Set timeZone to ? ToTemporalTimeZoneIdentifier(timeZone).
    4. Return ! CreateTemporalZonedDateTime(instant.[[EpochNanoseconds]], timeZone, "iso8601").

Note how the major step we are handling here is step 4, which is non-fallible. The fallible portion is in step 2 (engine specific step) and step 3 (handled by the conversion to TimeZone).

@lockels lockels force-pushed the instant_to_zdt_iso branch from 07984e3 to ccdfab4 Compare April 8, 2025 18:08
Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks as always!

@nekevss nekevss merged commit ac53b44 into boa-dev:main Apr 8, 2025
8 checks passed
@lockels lockels deleted the instant_to_zdt_iso branch April 8, 2025 21:54
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

Successfully merging this pull request may close these issues.

Implement toZonedDateTimeISO for Instant
2 participants