-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
Date
refactor
#3595
Date
refactor
#3595
Conversation
Test262 conformance changes
Fixed tests (16):
|
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #3595 +/- ##
==========================================
- Coverage 47.35% 47.33% -0.03%
==========================================
Files 475 475
Lines 45919 46138 +219
==========================================
+ Hits 21746 21839 +93
- Misses 24173 24299 +126 ☔ View full report in Codecov by Sentry. |
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.
Was taking a look at this. A lot of it looks great! Still have a bit more to review but wanted to run a question by you.
I think some of the utils in this have shared logic in the boa_temporal/utils
. Would it be better to share the logic from boa_temporal/utils
where possible instead of implementing it twice.
EDIT: Just checked the spec, the idea is actually to unify these but the blocker is 1087, but we seem to be treating the values in most case as the mathematical anyways. So it would probably be best to unify them where possible.
// 7. Let mn be 𝔽(ℝ(m) modulo 12). | ||
let mn = modulo(m, 12.0) as u8; | ||
|
||
// 8. Find a finite time value t such that YearFromTime(t) is ym, MonthFromTime(t) is mn, |
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 think there's an outstanding issue on MakeDay
here. Idk if it would be worth tracking it.
For reference
My first idea was that we may just go with the different implementations for now, until things like 1087 are resolved or the issue of how these are handeled in the spec is resolved. That way the temporal code could potentially evolve if needed and we have no cross cutting effort. But you are way more up to date on how the temporal spec, if you say the spec will probably not change considerably, I'm all for sharing the logic. One thing to keep in mind is maybe optimizations. My feeling is that there is at least some optimization potential in the Date logic. For example there are places where functions are called multiple times that could be avoided etc. I wanted to take a detailed look later on and I'm not sure how that would change the interoperability as some Date specific optimizations may require specific logic. |
We can keep it separate for now. I think some of this logic is fairly stable, so to speak, but there are still spec changes being made. I'd be surprised if the date equations changed much more, but airing on the cautious side doesn't hurt. Especially if there may be some places for optimizations as you said. |
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 good to me overall. Nice work! There were a couple more things I came across, but nothing blocking.
} | ||
|
||
// 2. Let truncated be ! ToIntegerOrInfinity(year). | ||
let truncated = IntegerOrInfinity::from(year); |
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: is IntegerOrInfinity
needed in this instance if we've already accounted for NaN?
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.
IIRC, IntegerOrInfinity
also rounds to an integer, so I think it's pretty much needed here.
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.
Yeah, I think it's just truncating.
So I was just wondering whether this step could just be year.trunc()
in this particular instance since the truncating here casts and then recasts back to f64.
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.
Hmmm that is true... IntegerOrInfinity
is mostly used to convert from f64
to an integer, or handle the non-finite edge cases, but here it's only used for the rounding...
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.
It can be left as is and merged. It was just something I saw when I was reviewing.
I think this could mostly be expressed as the below.
// Return non-finite cases
if !year.is_finite() {
return year
}
// truncate
let trunc = year.trunc();
// Check if value is in range.
if (0.0..=99.0).contains(&year) {
return 1900.0 + year
}
year
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 think I wanted to leave this for the optimizations later. For example in this case, every result of make_full_year
gets passed to make_day
afterwards. So there is definitley some potential to optimize this even across spec method boundaries.
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.
Really like the refactor! It's a shame we cannot fully use integers because of the range of i64
, but I think this is solved by Temporal
in a much better way.
This pull request refactors the
Date
builtin to align it with the spec and enable all tests to pass.The date operations by
chrono
are removed. This is necessary, becausechrono
only allows a limited date range fromJan 1, 262145 BCE
toDec 31, 262143 CE
. The spec allows for dates from-271821-04-20T00:00:00.000Z
to+275760-09-13T00:00:00.000Z
. Instead most datetime specific operations are now performed by the functions that the spec specifies. The only thing that is done by thetime
create is the calculation of local timzone offsets. All other usages ofchrono
are also removed so we can remove the dependency.