From 222c39600bc27fd1b79a00131780fe23e999c579 Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Fri, 5 Jan 2024 16:47:48 -0800 Subject: [PATCH] Fixup: display negative (#182) * fixup: fix bad conflict resolution on ab571d6ed0c4d345974f21a2b2731b27965abdf1 --- index.html | 2 +- spec.emu | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index b98bdee..0cbfdf4 100644 --- a/index.html +++ b/index.html @@ -2814,7 +2814,7 @@

1.1.6 GetDurationUnitOptions ( unit,

1.1.7 PartitionDurationFormatPattern ( durationFormat, duration )

The abstract operation PartitionDurationFormatPattern takes arguments durationFormat (a DurationFormat) and duration (a Duration Record) and returns a List. It creates and returns a List with all the corresponding parts 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. Let done be false.
  3. Let needSeparator be false.
  4. Let dataLocale be durationFormat.[[DataLocale]].
  5. Let dataLocaleData be %DurationFormat%.[[LocaleData]].[[<dataLocale>]].
  6. Let numberingSystem be durationFormat.[[NumberingSystem]].
  7. Let separator be dataLocaleData.[[digitalFormat]].[[<numberingSystem>]].
  8. While done is false, repeat for each row in Table 2 in table order, except the header row:
    1. Let value be the value of duration's field whose name is the Value Field value of the current row.
    2. Let style be the value of durationFormat's internal slot whose name is the Style Slot value of the current row.
    3. Let display be the value of durationFormat's internal slot whose name is the Display Slot value of the current row.
    4. Let unit be the Unit value of the current row.
    5. Let numberFormatUnit be the NumberFormat Unit value of the current row.
    6. Let nfOpts be OrdinaryObjectCreate(null).
    7. If unit is "seconds", "milliseconds", or "microseconds", then
      1. If unit is "seconds", then
        1. Let nextStyle be durationFormat.[[MillisecondsStyle]].
      2. Else if unit is "milliseconds", then
        1. Let nextStyle be durationFormat.[[MicrosecondsStyle]].
      3. Else,
        1. Let nextStyle be durationFormat.[[NanosecondsStyle]].
      4. If nextStyle is "numeric", then
        1. If unit is "seconds", then
          1. Set value to value + duration.[[Milliseconds]] / 103 + duration.[[Microseconds]] / 106 + duration.[[Nanoseconds]] / 109.
        2. Else if unit is "milliseconds", then
          1. Set value to value + duration.[[Microseconds]] / 103 + duration.[[Nanoseconds]] / 106.
        3. Else,
          1. Set value to value + duration.[[Nanoseconds]] / 103.
        4. If durationFormat.[[FractionalDigits]] is undefined, then
          1. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", 9๐”ฝ).
          2. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", +0๐”ฝ).
        5. Else,
          1. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", ๐”ฝ(durationFormat.[[FractionalDigits]])).
          2. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", ๐”ฝ(durationFormat.[[FractionalDigits]])).
        6. Perform ! CreateDataPropertyOrThrow(nfOpts, "roundingMode", "trunc").
        7. Set done to true.
    8. Let displayRequired be "false".
    9. Let hoursStyle be durationFormat.[[HoursStyle]].
    10. If unit is "minutes", then
      1. If hoursStyle is "numeric" or "2-digit", then
        1. Let hoursDisplay be durationFormat.[[HoursDisplay]].
        2. Let hoursValue be durationFormat.[[HoursValue]].
        3. If hoursDisplay is "always" or hoursValue is not 0, then
          1. Let secondsDisplay be durationFormat.[[SecondsDisplay]].
          2. Let secondsValue be durationFormat.[[SecondsValue]].
          3. If secondsDisplay is "always" or secondsValue is not 0, then
            1. Set displayRequired to "true".
    11. If value is not 0 or display is not "auto" or displayRequired is "true", then
      1. Perform ! CreateDataPropertyOrThrow(nfOpts, "numberingSystem", durationFormat.[[NumberingSystem]]).
      2. If style is "2-digit", then
        1. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumIntegerDigits", 2๐”ฝ).
      3. If style is neither "2-digit" nor "numeric", then
        1. Perform ! CreateDataPropertyOrThrow(nfOpts, "style", "unit").
        2. Perform ! CreateDataPropertyOrThrow(nfOpts, "unit", numberFormatUnit).
        3. Perform ! CreateDataPropertyOrThrow(nfOpts, "unitDisplay", style).
      4. Let nf be ! Construct(%NumberFormat%, ยซ durationFormat.[[Locale]], nfOpts ยป).
      5. If needSeparator is false, then
        1. Let list be a new empty List.
      6. Else,
        1. Let list be the last element of result.
        2. Append the Record { [[Type]]: "literal", [[Value]]: separator, [[Unit]]: empty } to list.
      7. Let parts be ! PartitionNumberPattern(nf, value).
      8. For each Record { [[Type]], [[Value]] } part of parts, do
        1. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: numberFormatUnit } to list.
      9. If needSeparator is false, then
        1. If style is "2-digit" or "numeric", then
          1. Set needSeparator to true.
        2. Append list to result.
    12. Else,
      1. Set needSeparator to false.
  9. Let lfOpts be OrdinaryObjectCreate(null).
  10. Perform ! CreateDataPropertyOrThrow(lfOpts, "type", "unit").
  11. Let listStyle be durationFormat.[[Style]].
  12. If listStyle is "digital", then
    1. Set listStyle to "short".
  13. Perform ! CreateDataPropertyOrThrow(lfOpts, "style", listStyle).
  14. Let lf be ! Construct(%ListFormat%, ยซ durationFormat.[[Locale]], lfOpts ยป).
  15. Let strings be a new empty List.
  16. For each element parts of result, do
    1. Let string be the empty String.
    2. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do
      1. Set string to the string-concatenation of string and part.[[Value]].
    3. Append string to strings.
  17. Let formatted be CreatePartsFromList(lf, strings).
  18. Let resultIndex be 0.
  19. Let resultLength be the number of elements in result.
  20. Let flattened be a new empty List.
  21. For each Record { [[Type]], [[Value]] } listPart in formatted, do
    1. If listPart.[[Type]] is "element", then
      1. Assert: resultIndex < resultLength.
      2. Let parts be result[resultIndex].
      3. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do
        1. Append part to flattened.
      4. Set resultIndex to resultIndex + 1.
    2. Else,
      1. Assert: listPart.[[Type]] is "literal".
      2. Append the Record { [[Type]]: "literal", [[Value]]: listPart.[[Value]], [[Unit]]: empty } to flattened.
  22. Return flattened.
+
  1. Let result be a new empty List.
  2. Let done be false.
  3. Let needSeparator be false.
  4. Let displayNegativeSign be true.
  5. Let dataLocale be durationFormat.[[DataLocale]].
  6. Let dataLocaleData be %DurationFormat%.[[LocaleData]].[[<dataLocale>]].
  7. Let numberingSystem be durationFormat.[[NumberingSystem]].
  8. Let separator be dataLocaleData.[[digitalFormat]].[[<numberingSystem>]].
  9. While done is false, repeat for each row in Table 2 in table order, except the header row:
    1. Let value be the value of duration's field whose name is the Value Field value of the current row.
    2. Let style be the value of durationFormat's internal slot whose name is the Style Slot value of the current row.
    3. Let display be the value of durationFormat's internal slot whose name is the Display Slot value of the current row.
    4. Let unit be the Unit value of the current row.
    5. Let numberFormatUnit be the NumberFormat Unit value of the current row.
    6. Let nfOpts be OrdinaryObjectCreate(null).
    7. If unit is "seconds", "milliseconds", or "microseconds", then
      1. If unit is "seconds", then
        1. Let nextStyle be durationFormat.[[MillisecondsStyle]].
      2. Else if unit is "milliseconds", then
        1. Let nextStyle be durationFormat.[[MicrosecondsStyle]].
      3. Else,
        1. Let nextStyle be durationFormat.[[NanosecondsStyle]].
      4. If nextStyle is "numeric", then
        1. If unit is "seconds", then
          1. Set value to value + duration.[[Milliseconds]] / 103 + duration.[[Microseconds]] / 106 + duration.[[Nanoseconds]] / 109.
        2. Else if unit is "milliseconds", then
          1. Set value to value + duration.[[Microseconds]] / 103 + duration.[[Nanoseconds]] / 106.
        3. Else,
          1. Set value to value + duration.[[Nanoseconds]] / 103.
        4. If durationFormat.[[FractionalDigits]] is undefined, then
          1. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", 9๐”ฝ).
          2. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", +0๐”ฝ).
        5. Else,
          1. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", ๐”ฝ(durationFormat.[[FractionalDigits]])).
          2. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", ๐”ฝ(durationFormat.[[FractionalDigits]])).
        6. Perform ! CreateDataPropertyOrThrow(nfOpts, "roundingMode", "trunc").
        7. Set done to true.
    8. Let displayRequired be "false".
    9. Let hoursStyle be durationFormat.[[HoursStyle]].
    10. If unit is "minutes", then
      1. If hoursStyle is "numeric" or "2-digit", then
        1. Let hoursDisplay be durationFormat.[[HoursDisplay]].
        2. Let hoursValue be durationFormat.[[HoursValue]].
        3. If hoursDisplay is "always" or hoursValue is not 0, then
          1. Let secondsDisplay be durationFormat.[[SecondsDisplay]].
          2. Let secondsValue be durationFormat.[[SecondsValue]].
          3. If secondsDisplay is "always" or secondsValue is not 0, then
            1. Set displayRequired to "true".
    11. If value is not 0 or display is not "auto" or displayRequired is "true", then
      1. If displayNegativeSign is true, then
        1. Set displayNegativeSign to false.
      2. Else,
        1. Perform ! CreateDataPropertyOrThrow(nfOpts, "signDisplay", "never").
      3. Perform ! CreateDataPropertyOrThrow(nfOpts, "numberingSystem", durationFormat.[[NumberingSystem]]).
      4. If style is "2-digit", then
        1. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumIntegerDigits", 2๐”ฝ).
      5. If style is neither "2-digit" nor "numeric", then
        1. Perform ! CreateDataPropertyOrThrow(nfOpts, "style", "unit").
        2. Perform ! CreateDataPropertyOrThrow(nfOpts, "unit", numberFormatUnit).
        3. Perform ! CreateDataPropertyOrThrow(nfOpts, "unitDisplay", style).
      6. Let nf be ! Construct(%NumberFormat%, ยซ durationFormat.[[Locale]], nfOpts ยป).
      7. If needSeparator is false, then
        1. Let list be a new empty List.
      8. Else,
        1. Let list be the last element of result.
        2. Append the Record { [[Type]]: "literal", [[Value]]: separator, [[Unit]]: empty } to list.
      9. Let parts be ! PartitionNumberPattern(nf, value).
      10. For each Record { [[Type]], [[Value]] } part of parts, do
        1. Append the Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: numberFormatUnit } to list.
      11. If needSeparator is false, then
        1. If style is "2-digit" or "numeric", then
          1. Set needSeparator to true.
        2. Append list to result.
    12. Else,
      1. Set needSeparator to false.
  10. Let lfOpts be OrdinaryObjectCreate(null).
  11. Perform ! CreateDataPropertyOrThrow(lfOpts, "type", "unit").
  12. Let listStyle be durationFormat.[[Style]].
  13. If listStyle is "digital", then
    1. Set listStyle to "short".
  14. Perform ! CreateDataPropertyOrThrow(lfOpts, "style", listStyle).
  15. Let lf be ! Construct(%ListFormat%, ยซ durationFormat.[[Locale]], lfOpts ยป).
  16. Let strings be a new empty List.
  17. For each element parts of result, do
    1. Let string be the empty String.
    2. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do
      1. Set string to the string-concatenation of string and part.[[Value]].
    3. Append string to strings.
  18. Let formatted be CreatePartsFromList(lf, strings).
  19. Let resultIndex be 0.
  20. Let resultLength be the number of elements in result.
  21. Let flattened be a new empty List.
  22. For each Record { [[Type]], [[Value]] } listPart in formatted, do
    1. If listPart.[[Type]] is "element", then
      1. Assert: resultIndex < resultLength.
      2. Let parts be result[resultIndex].
      3. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do
        1. Append part to flattened.
      4. Set resultIndex to resultIndex + 1.
    2. Else,
      1. Assert: listPart.[[Type]] is "literal".
      2. Append the Record { [[Type]]: "literal", [[Value]]: listPart.[[Value]], [[Unit]]: empty } to flattened.
  23. Return flattened.
Table 2: DurationFormat instance internal slots and properties relevant to PartitionDurationFormatPattern
diff --git a/spec.emu b/spec.emu index 3ae3453..b620ea4 100644 --- a/spec.emu +++ b/spec.emu @@ -252,6 +252,7 @@ contributors: Ujjwal Sharma, Younies Mahmoud 1. Let _result_ be a new empty List. 1. Let _done_ be *false*. 1. Let _needSeparator_ be *false*. + 1. Let _displayNegativeSign_ be *true*. 1. Let _dataLocale_ be _durationFormat_.[[DataLocale]]. 1. Let _dataLocaleData_ be %DurationFormat%.[[LocaleData]].[[<_dataLocale_>]]. 1. Let _numberingSystem_ be _durationFormat_.[[NumberingSystem]]. @@ -297,6 +298,10 @@ contributors: Ujjwal Sharma, Younies Mahmoud 1. If _secondsDisplay_ is *"always"* or _secondsValue_ is not 0, then 1. Set _displayRequired_ to *"true"*. 1. If _value_ is not 0 or _display_ is not *"auto"* or _displayRequired_ is *"true"*, then + 1. If _displayNegativeSign_ is *true*, then + 1. Set _displayNegativeSign_ to *false*. + 1. Else, + 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"signDisplay"*, *"never"*). 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"numberingSystem"*, _durationFormat_.[[NumberingSystem]]). 1. If _style_ is *"2-digit"*, then 1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"minimumIntegerDigits"*, *2*๐”ฝ).