-
Notifications
You must be signed in to change notification settings - Fork 20
Implementation of ZonedDateTime.prototype.with #267
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
Still unfinished, but this mostly works i think. |
src/builtins/core/date.rs
Outdated
|
||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! impl_with_fallback_method_zoned { |
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.
suggestion: change this to a normal method over a macro.
Since this is a one off and can't really take advantage of the other macro, it would probably be better for this to be a direct method implementation on PartialDate
so that it's easy to read and reason about in the future.
31/38 out of the current tests pass with my last commit. I'm unsure why 4 of the tests are saying this
This one for example overflow-options.js const zdt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789).toZonedDateTime("UTC");
const overflow = "constrain";
TemporalHelpers.assertZonedDateTimesEqual(
zdt.with({ month: 29 }, { overflow }),
Temporal.ZonedDateTime.from("1976-12-18T15:23:30.123456789+00:00[UTC]"));
TemporalHelpers.assertZonedDateTimesEqual(
zdt.with({ day: 31 }, { overflow }),
Temporal.ZonedDateTime.from("1976-11-30T15:23:30.123456789+00:00[UTC]"));
TemporalHelpers.assertZonedDateTimesEqual(
zdt.with({ hour: 29 }, { overflow }),
Temporal.ZonedDateTime.from("1976-11-18T23:23:30.123456789+00:00[UTC]"));
TemporalHelpers.assertZonedDateTimesEqual(
zdt.with({ nanosecond: 9000 }, { overflow }),
Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456999+00:00[UTC]")); and this one overflow-reject-throws.js const zdt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789).toZonedDateTime("UTC");
const overflow = "reject";
assert.throws(RangeError, () => zdt.with({ month: 29 }, { overflow }));
assert.throws(RangeError, () => zdt.with({ day: 31 }, { overflow }));
assert.throws(RangeError, () => zdt.with({ hour: 29 }, { overflow }));
assert.throws(RangeError, () => zdt.with({ nanosecond: 9000 }, { overflow })); |
I haven't inspected it yet, but some overflow option tests are not doing what they should, might be an erorr in the implementation of Overflow reject option here for example doesn't give the error variant. let provider = &FsTzdbProvider::default();
let zdt =
ZonedDateTime::try_new(217178610123456789, Calendar::default(), TimeZone::default())
.unwrap();
let overflow = ArithmeticOverflow::Reject;
let result_2 = zdt.with(
PartialZonedDateTime {
date: PartialDate {
day: Some(31),
..Default::default()
},
time: PartialTime::default(),
offset: None,
timezone: None,
},
None,
None,
Some(overflow),
provider,
);
assert!(result_2.is_err()); // Fails |
These are easy to answer. It looks like the implementation hasn't been "turned on" in Boa. That's partially my bad. I had a PR open yesterday to uncomment one of these methods, and I really should have searched for others. If you uncomment the lines in Boa, then it should hopefully pass 😄 The last case may genuinely be a bug that could be addressed. I haven't looked into it too much yet. If you want to dig into it, feel free to. |
c4c0450
to
969b124
Compare
Managed to fix this bug, was a simple error in my own code. I was previously always passing |
Thanks a lot, i honestly didn't think of that being the issue at all! But that seemed to fix it |
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.
I have one thought / question, it's not necessarily blocking (although I guess it is softly blocking due to curiosity on my part), but I'd be curious to hear your thoughts prior to approval / merge.
let offset_option = offset_option.unwrap_or(OffsetDisambiguation::Reject); | ||
|
||
// 23. Let dateTimeResult be ? InterpretTemporalDateTimeFields(calendar, fields, overflow). | ||
let result_date = self.calendar.date_from_partial( |
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 (non-blocking): this strikes me as a bit curious
Now that I'm looking at this in a bit more detail, I'm noticing that we have with_fallback_zoneddatetime
, but then we call get_iso_datetime_for
immediately after. Did you consider using the return value of get_iso_datetime_for
at all to calculate the fallback at all?
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 again for working on this! 😄
Fixes #260