From 9730552142500f6501176d6571238000e3fa74ea Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Sat, 13 Jan 2024 10:00:36 -0800 Subject: [PATCH] updated GetDurationUnitOptions to use new "fractional" style --- index.html | 10 +++++----- spec.emu | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index dcee5ef..cdcfebc 100644 --- a/index.html +++ b/index.html @@ -2804,10 +2804,10 @@

1.1.5 IsValidDurationRecord ( record

1.1.6 GetDurationUnitOptions ( unit, options, baseStyle, stylesList, digitalBase, prevStyle )

The abstract operation GetDurationUnitOptions takes arguments unit (a String), options (an Object), baseStyle (a String), stylesList (a List of Strings), digitalBase (a String), and prevStyle (a String) and returns either a normal completion containing a Record with [[Style]] and [[Display]] fields, or an abrupt completion. It extracts the relevant options for any given unit from an Object and returns them as a Record. It performs the following steps when called:

-
  1. Let style be ? GetOption(options, unit, string, stylesList, undefined).
  2. Let displayDefault be "always".
  3. If style is undefined, then
    1. If baseStyle is "digital", then
      1. If unit is not one of "hours", "minutes", or "seconds", then
        1. Set displayDefault to "auto".
      2. Set style to digitalBase.
    2. Else,
      1. If prevStyle is "numeric" or "2-digit", then
        1. If unit is not one of "minutes" or "seconds", then
          1. Set displayDefault to "auto".
        2. Set style to "numeric".
      2. Else,
        1. Set displayDefault to "auto".
        2. Set style to baseStyle.
  4. Else if style is "numeric" and unit is one of "milliseconds", "microseconds", or "nanoseconds", then
    1. Set displayDefault to "auto".
  5. Let displayField be the string-concatenation of unit and "Display".
  6. Let display be ? GetOption(options, displayField, string, « "auto", "always" », displayDefault).
  7. If prevStyle is "numeric" or "2-digit", then
    1. If style is not "numeric" or "2-digit", then
      1. Throw a RangeError exception.
    2. Else if unit is "minutes" or "seconds", then
      1. Set style to "2-digit".
  8. If style is "numeric" and display is "always" and unit is one of "milliseconds", "microseconds", or "nanoseconds", then
    1. Throw a RangeError exception.
  9. Return the Record { - [[Style]]: style, - [[Display]]: display - }.
+
  1. Let style be ? GetOption(options, unit, string, stylesList, undefined).
  2. Let displayDefault be "always".
  3. If style is undefined, then
    1. If baseStyle is "digital", then
      1. If unit is not one of "hours", "minutes", or "seconds", then
        1. Set displayDefault to "auto".
      2. Set style to digitalBase.
    2. Else,
      1. If prevStyle is "fractional", "numeric" or "2-digit", then
        1. If unit is not one of "minutes" or "seconds", then
          1. Set displayDefault to "auto".
        2. If unit is one of "milliseconds", "microseconds", or "nanoseconds", then
          1. Set style to "fractional".
        3. Else,
          1. Set style to "numeric".
      2. Else,
        1. Set displayDefault to "auto".
        2. Set style to baseStyle.
  4. Else if style is "fractional", then
    1. Set displayDefault to "auto".
  5. Let displayField be the string-concatenation of unit and "Display".
  6. Let display be ? GetOption(options, displayField, string, « "auto", "always" », displayDefault).
  7. If display is "always" and style is "fractional", then
    1. Throw a RangeError exception.
  8. If prevStyle is "fractional", then
    1. If style is not "fractional", then
      1. Throw a RangeError exception.
  9. If prevStyle is "numeric" or "2-digit", then
    1. If style is not "fractional", "numeric" or "2-digit", then
      1. Throw a RangeError exception.
    2. If unit is "minutes" or "seconds", then
      1. Set style to "2-digit".
  10. Return the Record { + [[Style]]: style, + [[Display]]: display + }.
@@ -3244,4 +3244,4 @@

Software License

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

- \ No newline at end of file + diff --git a/spec.emu b/spec.emu index 00fbde8..fbd0514 100644 --- a/spec.emu +++ b/spec.emu @@ -211,24 +211,30 @@ contributors: Ujjwal Sharma, Younies Mahmoud 1. Set _displayDefault_ to *"auto"*. 1. Set _style_ to _digitalBase_. 1. Else, - 1. If _prevStyle_ is *"numeric"* or *"2-digit"*, then + 1. If _prevStyle_ is *"fractional"*, *"numeric"* or *"2-digit"*, then 1. If _unit_ is not one of *"minutes"* or *"seconds"*, then 1. Set _displayDefault_ to *"auto"*. - 1. Set _style_ to *"numeric"*. + 1. If _unit_ is one of *"milliseconds"*, *"microseconds"*, or *"nanoseconds"*, then + 1. Set _style_ to *"fractional"*. + 1. Else, + 1. Set _style_ to *"numeric"*. 1. Else, 1. Set _displayDefault_ to *"auto"*. 1. Set _style_ to _baseStyle_. - 1. Else if _style_ is *"numeric"* and _unit_ is one of *"milliseconds"*, *"microseconds"*, or *"nanoseconds"*, then + 1. Else if _style_ is *"fractional"*, then 1. Set _displayDefault_ to *"auto"*. 1. Let _displayField_ be the string-concatenation of _unit_ and *"Display"*. 1. Let _display_ be ? GetOption(_options_, _displayField_, ~string~, « *"auto"*, *"always"* », _displayDefault_). + 1. If _display_ is *"always"* and _style_ is *"fractional"*, then + 1. Throw a *RangeError* exception. + 1. If _prevStyle_ is *"fractional"*, then + 1. If _style_ is not *"fractional"*, then + 1. Throw a *RangeError* exception. 1. If _prevStyle_ is *"numeric"* or *"2-digit"*, then - 1. If _style_ is not *"numeric"* or *"2-digit"*, then + 1. If _style_ is not *"fractional"*, *"numeric"* or *"2-digit"*, then 1. Throw a *RangeError* exception. - 1. Else if _unit_ is *"minutes"* or *"seconds"*, then + 1. If _unit_ is *"minutes"* or *"seconds"*, then 1. Set _style_ to *"2-digit"*. - 1. If _style_ is *"numeric"* and _display_ is *"always"* and _unit_ is one of *"milliseconds"*, *"microseconds"*, or *"nanoseconds"*, then - 1. Throw a *RangeError* exception. 1. Return the Record { [[Style]]: _style_, [[Display]]: _display_