-
Notifications
You must be signed in to change notification settings - Fork 19
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
Conversation
Huh.. strange that one of the tests fail here.. Passes locally, and that file is not touched by this PR |
Huh, are you running on an ubuntu distro? Also, have you rebased to main for this PR? |
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 |
src/builtins/core/timezone.rs
Outdated
@@ -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(); |
There was a problem hiding this comment.
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
).
75577d7
to
2fc0cac
Compare
Nope, makes sense why it fails since i'm on a mac.
Nope, but i think i managed to fix that now. I'll convert this PR to a draft for now.. |
6bbd835
to
2e3e513
Compare
src/builtins/core/instant.rs
Outdated
@@ -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> { |
There was a problem hiding this comment.
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
).
07984e3
to
ccdfab4
Compare
There was a problem hiding this 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!
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.