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

Implement arithmetic and rounding relative to ZonedDateTime #1171

Closed
4 tasks done
ptomato opened this issue Nov 10, 2020 · 0 comments · Fixed by #1185
Closed
4 tasks done

Implement arithmetic and rounding relative to ZonedDateTime #1171

ptomato opened this issue Nov 10, 2020 · 0 comments · Fixed by #1185
Assignees
Labels
non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE! spec-text Specification text involved

Comments

@ptomato
Copy link
Collaborator

ptomato commented Nov 10, 2020

This is a separate issue that covers the last point in the checklists in #856 and #569, which are actually the same thing. I suspect that all the code for these is the same.

  • implement ZonedDateTime as relativeTo parameter in Duration.round() method
  • implement ZonedDateTime as relativeTo parameter in Duration.total() method
  • implement ZonedDateTime as relativeTo parameter in Duration.add() and subtract() methods
  • fix ZonedDateTime.round() case when rounding to the nearest day and that day is ≠24 hours long
@ptomato ptomato added spec-text Specification text involved non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE! labels Nov 10, 2020
@ptomato ptomato added this to the Stable proposal milestone Nov 10, 2020
@ptomato ptomato self-assigned this Nov 10, 2020
ptomato added a commit that referenced this issue Nov 12, 2020
This splits the rounding operation out of DifferenceZonedDateTime. It
should be followed by RoundDuration and then by AdjustRoundedDurationDays
if necessary.

This also allows RoundDuration to take a ZonedDateTime as its relativeTo
parameter (though it doesn't work yet in all cases.)

AdjustRoundedDurationDays does a second round operation if the time part
of the duration has rounded up to exceed the day length. It should be
called after AdjustRoundedDurationDays if necessary. Sometimes it is not:
it's only needed if relativeTo is a ZonedDateTime, and it's not needed in
Duration.total() (because the fractional days returned would be the same
regardless.)

See: #1171
ptomato added a commit that referenced this issue Nov 12, 2020
This new abstract operation will be used in more places when converting
nanoseconds to time-zone-aware days.

See: #1171
ptomato added a commit that referenced this issue Nov 12, 2020
These tests don't work yet, but it's nonetheless good to have them
reviewed and landed in the test suite.

See: #1171
ptomato added a commit that referenced this issue Nov 12, 2020
This splits the rounding operation out of DifferenceZonedDateTime. It
should be followed by RoundDuration and then by AdjustRoundedDurationDays
if necessary.

This also allows RoundDuration to take a ZonedDateTime as its relativeTo
parameter (though it doesn't work yet in all cases.)

AdjustRoundedDurationDays does a second round operation if the time part
of the duration has rounded up to exceed the day length. It should be
called after AdjustRoundedDurationDays if necessary. Sometimes it is not:
it's only needed if relativeTo is a ZonedDateTime, and it's not needed in
Duration.total() (because the fractional days returned would be the same
regardless.)

See: #1171
ptomato added a commit that referenced this issue Nov 12, 2020
This new abstract operation will be used in more places when converting
nanoseconds to time-zone-aware days.

See: #1171
ptomato added a commit that referenced this issue Nov 12, 2020
These tests don't work yet, but it's nonetheless good to have them
reviewed and landed in the test suite.

See: #1171
ptomato added a commit that referenced this issue Nov 12, 2020
This splits the rounding operation out of DifferenceZonedDateTime. It
should be followed by RoundDuration and then by AdjustRoundedDurationDays
if necessary.

This also allows RoundDuration to take a ZonedDateTime as its relativeTo
parameter (though it doesn't work yet in all cases.)

AdjustRoundedDurationDays does a second round operation if the time part
of the duration has rounded up to exceed the day length. It should be
called after AdjustRoundedDurationDays if necessary. Sometimes it is not:
it's only needed if relativeTo is a ZonedDateTime, and it's not needed in
Duration.total() (because the fractional days returned would be the same
regardless.)

See: #1171
ptomato added a commit that referenced this issue Nov 12, 2020
This new abstract operation will be used in more places when converting
nanoseconds to time-zone-aware days.

See: #1171
ptomato added a commit that referenced this issue Nov 12, 2020
These tests don't work yet, but it's nonetheless good to have them
reviewed and landed in the test suite.

See: #1171
ptomato added a commit that referenced this issue Nov 13, 2020
This new abstract operation will be used in more places when converting
nanoseconds to time-zone-aware days.

See: #1171
ptomato added a commit that referenced this issue Nov 13, 2020
These tests don't work yet, but it's nonetheless good to have them
reviewed and landed in the test suite.

See: #1171
ptomato added a commit that referenced this issue Nov 13, 2020
These tests don't work yet, but it's nonetheless good to have them
reviewed and landed in the test suite.

See: #1171
ptomato added a commit that referenced this issue Nov 13, 2020
This splits the rounding operation out of DifferenceZonedDateTime. It
should be followed by RoundDuration and then by AdjustRoundedDurationDays
if necessary.

This also allows RoundDuration to take a ZonedDateTime as its relativeTo
parameter (though it doesn't work yet in all cases.)

AdjustRoundedDurationDays does a second round operation if the time part
of the duration has rounded up to exceed the day length. It should be
called after AdjustRoundedDurationDays if necessary. Sometimes it is not:
it's only needed if relativeTo is a ZonedDateTime, and it's not needed in
Duration.total() (because the fractional days returned would be the same
regardless.)

See: #1171
ptomato added a commit that referenced this issue Nov 13, 2020
This new abstract operation will be used in more places when converting
nanoseconds to time-zone-aware days.

See: #1171
ptomato added a commit that referenced this issue Nov 13, 2020
These tests don't work yet, but it's nonetheless good to have them
reviewed and landed in the test suite.

See: #1171
ptomato added a commit that referenced this issue Nov 13, 2020
duration.add(other, { relativeTo }) is by definition equal to
relativeTo.until(relativeTo.add(duration).add(other)), so rewrite
AddDuration to work that way.

See: #1171
ptomato added a commit that referenced this issue Nov 13, 2020
Adds a day length parameter to RoundDateTime and RoundTime in order to
take non-24-hour days into account when rounding a time to the nearest
day.

See: #1171
Ms2ger added a commit that referenced this issue Nov 13, 2020
Adds a day length parameter to RoundDateTime and RoundTime in order to
take non-24-hour days into account when rounding a time to the nearest
day.

See: #1171

Co-authored-by: Ms2ger <[email protected]>
Ms2ger pushed a commit that referenced this issue Nov 13, 2020
duration.add(other, { relativeTo }) is by definition equal to
relativeTo.until(relativeTo.add(duration).add(other)), so rewrite
AddDuration to work that way.

See: #1171
Ms2ger added a commit that referenced this issue Nov 13, 2020
Adds a day length parameter to RoundDateTime and RoundTime in order to
take non-24-hour days into account when rounding a time to the nearest
day.

See: #1171

Co-authored-by: Ms2ger <[email protected]>
ptomato added a commit that referenced this issue Nov 13, 2020
In case you need to round the remainder of nanoseconds to the nearest day,
you need to know how long the day is. This will be used to fix rounding
relative to a ZonedDateTime.

See: #1171
ptomato added a commit that referenced this issue Nov 13, 2020
When rounding or totaling time units, the length of the last day needs to
be taken into account if relativeTo is a ZonedDateTime. This fixes some of
the broken test cases.

See: #1171
ptomato added a commit that referenced this issue Nov 13, 2020
When converting between days and lower units in BalanceDuration, we need
to take the offset shift into account, and likewise when converting
between lower units and days, we need to take the length of the last day
into account.

See: #1171
ptomato added a commit that referenced this issue Nov 14, 2020
In case you need to round the remainder of nanoseconds to the nearest day,
you need to know how long the day is. This will be used to fix rounding
relative to a ZonedDateTime.

See: #1171
ptomato added a commit that referenced this issue Nov 14, 2020
When rounding or totaling time units, the length of the last day needs to
be taken into account if relativeTo is a ZonedDateTime. This fixes some of
the broken test cases.

See: #1171
ptomato added a commit that referenced this issue Nov 14, 2020
When converting between days and lower units in BalanceDuration, we need
to take the offset shift into account, and likewise when converting
between lower units and days, we need to take the length of the last day
into account.

See: #1171
ptomato added a commit that referenced this issue Nov 14, 2020
When converting between days and lower units in BalanceDuration, we need
to take the exact time into account, and likewise when converting
between lower units and days, we need to take the length of the last day
into account.

See: #1171
ptomato added a commit that referenced this issue Nov 15, 2020
When converting between days and lower units in BalanceDuration, we need
to take the exact time into account, and likewise when converting
between lower units and days, we need to take the length of the last day
into account.

See: #1171
ptomato added a commit that referenced this issue Nov 15, 2020
When converting between days and lower units in BalanceDuration, we need
to take the exact time into account, and likewise when converting
between lower units and days, we need to take the length of the last day
into account. As well, we need to take into account the possibility of
moving the time forward when adding, due to disambiguation.

These were handled correctly in DifferenceZonedDateTime but not in
NanosecondsToDays. In order to ensure that these algorithms don't diverge,
move all the important stuff from DifferenceZonedDateTime into
NanosecondsToDays, and use NanosecondsToDays in DifferenceZonedDateTime.

See: #1171
Ms2ger pushed a commit that referenced this issue Nov 16, 2020
In case you need to round the remainder of nanoseconds to the nearest day,
you need to know how long the day is. This will be used to fix rounding
relative to a ZonedDateTime.

See: #1171
Ms2ger pushed a commit that referenced this issue Nov 16, 2020
When rounding or totaling time units, the length of the last day needs to
be taken into account if relativeTo is a ZonedDateTime. This fixes some of
the broken test cases.

See: #1171
Ms2ger pushed a commit that referenced this issue Nov 16, 2020
When converting between days and lower units in BalanceDuration, we need
to take the exact time into account, and likewise when converting
between lower units and days, we need to take the length of the last day
into account. As well, we need to take into account the possibility of
moving the time forward when adding, due to disambiguation.

These were handled correctly in DifferenceZonedDateTime but not in
NanosecondsToDays. In order to ensure that these algorithms don't diverge,
move all the important stuff from DifferenceZonedDateTime into
NanosecondsToDays, and use NanosecondsToDays in DifferenceZonedDateTime.

See: #1171
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE! spec-text Specification text involved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant