Skip to content

Commit

Permalink
Normative: Change internal slots of Duration to store mathematical va…
Browse files Browse the repository at this point in the history
…lues

This changes the internal slots of Duration to store mathematical values
instead of Number values. However, only mathematical values that are (1)
integers, and (2) representable by Number values, are allowed. This is
achieved by storing ℝ(𝔽(_value_)) in the internal slots of Durations and
in the fields of Duration Records.

This should solve the problem of type confusion between Number values and
mathematical values, and eliminate places where operations only defined on
mathematical values (such as abs() and floor()) were applied to the Number
domain.

This is a normative change because it means that it is now impossible for
the Number values NaN, +Infinity, -Infinity, and -0, as well as any
non-integer Number values, and not-exactly-representable Number values
>MAX_SAFE_INTEGER, to be exposed to JS via the property getters of
Temporal.Duration. I suspect this was not possible previously with NaN and
non-integer Numbers, I suspect it may have been possible with infinities
and >MAX_SAFE_INTEGER, and it was definitely possible with -0.

Closes: #1604
Closes: #1715
  • Loading branch information
ptomato committed Mar 30, 2022
1 parent 39eeecd commit 1f3fba8
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 147 deletions.
2 changes: 1 addition & 1 deletion spec/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ <h1>Temporal.Calendar.prototype.dateAdd ( _date_, _duration_ [ , _options_ ] )</
1. Set _duration_ to ? ToTemporalDuration(_duration_).
1. Set _options_ to ? GetOptionsObject(_options_).
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Let _balanceResult_ be ! BalanceDuration(_duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], *"day"*).
1. Let _balanceResult_ be ? BalanceDuration(_duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], *"day"*).
1. Let _result_ be ? AddISODate(_date_.[[ISOYear]], _date_.[[ISOMonth]], _date_.[[ISODay]], _duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _balanceResult_.[[Days]], _overflow_).
1. Return ? CreateTemporalDate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _calendar_).
</emu-alg>
Expand Down
Loading

0 comments on commit 1f3fba8

Please sign in to comment.