From 68b00f3f272ea5a1bbcd37588da66d07f2d3507d Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Mon, 12 Aug 2024 09:31:45 -0700 Subject: [PATCH] update @FrankYFTang PR 198 "useGrouping" for refactored numeric units formatting (#198) Co-authored-by: Ben Allen --- index.html | 8 ++++---- spec.emu | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 74ecea6..6941b7b 100644 --- a/index.html +++ b/index.html @@ -2693,7 +2693,7 @@

Stage 3 Draft / August 7, 2024

Intl.DurationFormat

+

Stage 3 Draft / August 9, 2024

Intl.DurationFormat

1 DurationFormat Objects

@@ -2829,21 +2829,21 @@

1.1.8 NextUnitFractional ( durationFormat1.1.9 FormatNumericHours ( durationFormat, hoursValue, signDisplayed )

The abstract operation FormatNumericHours takes arguments durationFormat (a DurationFormat object), hoursValue (an integer), and signDisplayed (a Boolean) and returns a List of Records. It creates a List of Records containing the formatted parts of hoursValue interpreted as the value of a Duration Record's [[Hours]] field according to the effective locale and the formatting options of durationFormat. It performs the following steps when called:

-
  1. Let hoursStyle be durationFormat.[[HoursStyle]].
  2. Assert: hoursStyle is "numeric" or hoursStyle is "2-digit".
  3. Let result be a new empty List.
  4. Let nfOpts be OrdinaryObjectCreate(null).
  5. Let numberingSystem be durationFormat.[[NumberingSystem]].
  6. Perform ! CreateDataPropertyOrThrow(nfOpts, "numberingSystem", numberingSystem).
  7. If hoursStyle is "2-digit", then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumIntegerDigits", 2𝔽).
  8. If signDisplayed is false, then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "signDisplay", "never").
  9. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
  10. Let hoursParts be ! PartitionNumberPattern(nf, hoursValue).
  11. For each Record { [[Type]], [[Value]] } part of hoursParts, do
    1. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: "hour" } to result.
  12. Return result.
+
  1. Let hoursStyle be durationFormat.[[HoursStyle]].
  2. Assert: hoursStyle is "numeric" or hoursStyle is "2-digit".
  3. Let result be a new empty List.
  4. Let nfOpts be OrdinaryObjectCreate(null).
  5. Let numberingSystem be durationFormat.[[NumberingSystem]].
  6. Perform ! CreateDataPropertyOrThrow(nfOpts, "numberingSystem", numberingSystem).
  7. If hoursStyle is "2-digit", then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumIntegerDigits", 2𝔽).
  8. If signDisplayed is false, then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "signDisplay", "never").
  9. Perform ! CreateDataPropertyOrThrow(nfOpts, "useGrouping", false).
  10. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
  11. Let hoursParts be ! PartitionNumberPattern(nf, hoursValue).
  12. For each Record { [[Type]], [[Value]] } part of hoursParts, do
    1. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: "hour" } to result.
  13. Return result.

1.1.10 FormatNumericMinutes ( durationFormat, minutesValue, hoursDisplayed, signDisplayed )

The abstract operation FormatNumericMinutes takes arguments durationFormat (a DurationFormat Object), minutesValue (an integer), hoursDisplayed (a Boolean), and signDisplayed (a Boolean) and returns a List of Records. It creates a List of Records containing the formatted parts of minutesValue interpreted as the value of a Duration Record's [[Minutes]] field according to the effective locale and the formatting options of durationFormat. It performs the following steps when called:

-
  1. Let result be a new empty List.
  2. If hoursDisplayed is true, then
    1. Let separator be durationFormat.[[DigitalFormat]].[[HoursMinutesSeparator]].
    2. Append the Record { [[Type]]: "literal", [[Value]]: separator, [[Unit]]: empty } to result.
  3. Let minutesStyle be durationFormat.[[MinutesStyle]].
  4. Assert: minutesStyle is "numeric" or minutesStyle is "2-digit".
  5. Let nfOpts be OrdinaryObjectCreate(null).
  6. Let numberingSystem be durationFormat.[[NumberingSystem]].
  7. Perform ! CreateDataPropertyOrThrow(nfOpts, "numberingSystem", numberingSystem).
  8. If minutesStyle is "2-digit", then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumIntegerDigits", 2𝔽).
  9. If signDisplayed is false, then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "signDisplay", "never").
  10. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
  11. Let minutesParts be ! PartitionNumberPattern(nf, minutesValue).
  12. For each Record { [[Type]], [[Value]] } part of minutesParts, do
    1. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: "minute" } to result.
  13. Return result.
+
  1. Let result be a new empty List.
  2. If hoursDisplayed is true, then
    1. Let separator be durationFormat.[[DigitalFormat]].[[HoursMinutesSeparator]].
    2. Append the Record { [[Type]]: "literal", [[Value]]: separator, [[Unit]]: empty } to result.
  3. Let minutesStyle be durationFormat.[[MinutesStyle]].
  4. Assert: minutesStyle is "numeric" or minutesStyle is "2-digit".
  5. Let nfOpts be OrdinaryObjectCreate(null).
  6. Let numberingSystem be durationFormat.[[NumberingSystem]].
  7. Perform ! CreateDataPropertyOrThrow(nfOpts, "numberingSystem", numberingSystem).
  8. If minutesStyle is "2-digit", then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumIntegerDigits", 2𝔽).
  9. If signDisplayed is false, then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "signDisplay", "never").
  10. Perform ! CreateDataPropertyOrThrow(nfOpts, "useGrouping", false).
  11. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
  12. Let minutesParts be ! PartitionNumberPattern(nf, minutesValue).
  13. For each Record { [[Type]], [[Value]] } part of minutesParts, do
    1. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: "minute" } to result.
  14. Return result.

1.1.11 FormatNumericSeconds ( durationFormat, secondsValue, minutesDisplayed, signDisplayed )

The abstract operation FormatNumericSeconds takes arguments durationFormat (a DurationFormat Object), secondsValue (an integer), minutesDisplayed (a Boolean), and signDisplayed (a Boolean) and returns a List of Records. It creates a List of Records containing the formatted parts of secondsValue interpreted as the value of a Duration Record's [[Seconds]] field according to the effective locale and the formatting options of durationFormat. It performs the following steps when called:

-
  1. Let secondsStyle be durationFormat.[[SecondsStyle]].
  2. Assert: secondsStyle is "numeric" or secondsStyle is "2-digit".
  3. Let result be a new empty List.
  4. If minutesDisplayed is true, then
    1. Let separator be durationFormat.[[DigitalFormat]].[[MinutesSecondsSeparator]].
    2. Append the Record { [[Type]]: "literal", [[Value]]: separator, [[Unit]]: empty } to result.
  5. Let nfOpts be OrdinaryObjectCreate(null).
  6. Let numberingSystem be durationFormat.[[NumberingSystem]].
  7. Perform ! CreateDataPropertyOrThrow(nfOpts, "numberingSystem", numberingSystem).
  8. If secondsStyle is "2-digit", then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumIntegerDigits", 2𝔽).
  9. If signDisplayed is false, then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "signDisplay", "never").
  10. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
  11. If durationFormat.[[FractionalDigits]] is undefined, then
    1. Let maximumFractionDigits be 9𝔽.
    2. Let minimumFractionDigits be +0𝔽.
  12. Else,
    1. Let maximumFractionDigits be durationFormat.[[FractionalDigits]].
    2. Let minimumFractionDigits be durationFormat.[[FractionalDigits]].
  13. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", maximumFractionDigits).
  14. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", minimumFractionDigits).
  15. Perform ! CreateDataPropertyOrThrow(nfOpts, "roundingMode", "trunc").
  16. Let secondsParts be ! PartitionNumberPattern(nf, secondsValue).
  17. For each Record { [[Type]], [[Value]] } part of secondsParts, do
    1. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: "second" } to result.
  18. Return result.
+
  1. Let secondsStyle be durationFormat.[[SecondsStyle]].
  2. Assert: secondsStyle is "numeric" or secondsStyle is "2-digit".
  3. Let result be a new empty List.
  4. If minutesDisplayed is true, then
    1. Let separator be durationFormat.[[DigitalFormat]].[[MinutesSecondsSeparator]].
    2. Append the Record { [[Type]]: "literal", [[Value]]: separator, [[Unit]]: empty } to result.
  5. Let nfOpts be OrdinaryObjectCreate(null).
  6. Let numberingSystem be durationFormat.[[NumberingSystem]].
  7. Perform ! CreateDataPropertyOrThrow(nfOpts, "numberingSystem", numberingSystem).
  8. If secondsStyle is "2-digit", then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumIntegerDigits", 2𝔽).
  9. If signDisplayed is false, then
    1. Perform ! CreateDataPropertyOrThrow(nfOpts, "signDisplay", "never").
  10. Perform ! CreateDataPropertyOrThrow(nfOpts, "useGrouping", false).
  11. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
  12. If durationFormat.[[FractionalDigits]] is undefined, then
    1. Let maximumFractionDigits be 9𝔽.
    2. Let minimumFractionDigits be +0𝔽.
  13. Else,
    1. Let maximumFractionDigits be durationFormat.[[FractionalDigits]].
    2. Let minimumFractionDigits be durationFormat.[[FractionalDigits]].
  14. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", maximumFractionDigits).
  15. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", minimumFractionDigits).
  16. Perform ! CreateDataPropertyOrThrow(nfOpts, "roundingMode", "trunc").
  17. Let secondsParts be ! PartitionNumberPattern(nf, secondsValue).
  18. For each Record { [[Type]], [[Value]] } part of secondsParts, do
    1. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: "second" } to result.
  19. Return result.
diff --git a/spec.emu b/spec.emu index 3eed823..558468d 100644 --- a/spec.emu +++ b/spec.emu @@ -340,6 +340,7 @@ contributors: Ujjwal Sharma, Younies Mahmoud 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"minimumIntegerDigits"*, *2*𝔽). 1. If _signDisplayed_ is *false*, then 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"signDisplay"*, *"never"*). + 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"useGrouping"*, *false*). 1. Let _nf_ be ! Construct(%NumberFormat%, « _durationFormat_.[[Locale]], _nfOpts_ »). 1. Let _hoursParts_ be ! PartitionNumberPattern(_nf_, _hoursValue_). 1. For each Record { [[Type]], [[Value]] } _part_ of _hoursParts_, do @@ -376,6 +377,7 @@ contributors: Ujjwal Sharma, Younies Mahmoud 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"minimumIntegerDigits"*, *2*𝔽). 1. If _signDisplayed_ is *false*, then 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"signDisplay"*, *"never"*). + 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"useGrouping"*, *false*). 1. Let _nf_ be ! Construct(%NumberFormat%, « _durationFormat_.[[Locale]], _nfOpts_ »). 1. Let _minutesParts_ be ! PartitionNumberPattern(_nf_, _minutesValue_). 1. For each Record { [[Type]], [[Value]] } _part_ of _minutesParts_, do @@ -412,6 +414,7 @@ contributors: Ujjwal Sharma, Younies Mahmoud 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"minimumIntegerDigits"*, *2*𝔽). 1. If _signDisplayed_ is *false*, then 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"signDisplay"*, *"never"*). + 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"useGrouping"*, *false*). 1. Let _nf_ be ! Construct(%NumberFormat%, « _durationFormat_.[[Locale]], _nfOpts_ »). 1. If _durationFormat_.[[FractionalDigits]] is *undefined*, then 1. Let _maximumFractionDigits_ be *9*𝔽.