Skip to content

Commit d097048

Browse files
gibson042ryzokuken
authored andcommitted
Editorial: Simplify GetDurationUnitOptions
1 parent e3d3406 commit d097048

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

spec/durationformat.html

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -626,40 +626,46 @@ <h1>
626626
1. Let _displayDefault_ be *"always"*.
627627
1. If _style_ is *undefined*, then
628628
1. If _baseStyle_ is *"digital"*, then
629-
1. If _unit_ is not one of *"hours"*, *"minutes"*, or *"seconds"*, then
630-
1. Set _displayDefault_ to *"auto"*.
631629
1. Set _style_ to _digitalBase_.
630+
1. If _unit_ is not one of *"hours"*, *"minutes"*, or *"seconds"*, set _displayDefault_ to *"auto"*.
631+
1. Else if _prevStyle_ is one of *"fractional"*, *"numeric"* or *"2-digit"*, then
632+
1. Set _style_ to *"numeric"*.
633+
1. If _unit_ is not *"minutes"* or *"seconds"*, set _displayDefault_ to *"auto"*.
632634
1. Else,
633-
1. If _prevStyle_ is *"fractional"*, *"numeric"* or *"2-digit"*, then
634-
1. If _unit_ is not one of *"minutes"* or *"seconds"*, then
635-
1. Set _displayDefault_ to *"auto"*.
636-
1. Set _style_ to *"numeric"*.
637-
1. Else,
638-
1. Set _displayDefault_ to *"auto"*.
639-
1. Set _style_ to _baseStyle_.
640-
1. If _style_ is *"numeric"*, then
641-
1. If _unit_ is one of *"milliseconds"*, *"microseconds"*, or *"nanoseconds"*, then
642-
1. Set _style_ to *"fractional"*.
635+
1. Set _style_ to _baseStyle_.
643636
1. Set _displayDefault_ to *"auto"*.
637+
1. If _style_ is *"numeric"* and _unit_ is one of *"milliseconds"*, *"microseconds"*, or *"nanoseconds"*, then
638+
1. Set _style_ to *"fractional"*.
639+
1. Set _displayDefault_ to *"auto"*.
644640
1. Let _displayField_ be the string-concatenation of _unit_ and *"Display"*.
645641
1. Let _display_ be ? GetOption(_options_, _displayField_, ~string~, « *"auto"*, *"always"* », _displayDefault_).
646-
1. If _display_ is *"always"* and _style_ is *"fractional"*, then
647-
1. Throw a *RangeError* exception.
648-
1. If _prevStyle_ is *"fractional"*, then
649-
1. If _style_ is not *"fractional"*, then
650-
1. Throw a *RangeError* exception.
651-
1. If _prevStyle_ is *"numeric"* or *"2-digit"*, then
652-
1. If _style_ is not *"fractional"*, *"numeric"* or *"2-digit"*, then
653-
1. Throw a *RangeError* exception.
654-
1. If _unit_ is *"minutes"* or *"seconds"*, then
655-
1. Set _style_ to *"2-digit"*.
656-
1. If _unit_ is *"hours"* and _twoDigitHours_ is *true*, then
657-
1. Set _style_ to *"2-digit"*.
642+
1. Perform ? ValidateDurationUnitStyle(_unit_, _style_, _display_, _prevStyle_).
643+
1. If _unit_ is *"hours"* and _twoDigitHours_ is *true*, set _style_ to *"2-digit"*.
644+
1. If _unit_ is *"minutes"* or *"seconds"* and _prevStyle_ is *"numeric"* or *"2-digit"*, set _style_ to *"2-digit"*.
658645
1. Return the Record {
659646
[[Style]]: _style_,
660647
[[Display]]: _display_
661648
}.
662649
</emu-alg>
650+
651+
<emu-clause id="sec-stringpaddingbuiltinsimpl" type="abstract operation">
652+
<h1>
653+
ValidateDurationUnitStyle (
654+
_unit_: a String,
655+
_style_: a String,
656+
_display_: a String,
657+
_prevStyle_: a String,
658+
): either a normal completion containing ~unused~ or a throw completion
659+
</h1>
660+
<dl class="header">
661+
</dl>
662+
<emu-alg>
663+
1. If _display_ is *"always"* and _style_ is *"fractional"*, throw a *RangeError* exception.
664+
1. If _prevStyle_ is *"fractional"* and _style_ is not *"fractional"*, throw a *RangeError* exception.
665+
1. If _prevStyle_ is *"numeric"* or *"2-digit"* and _style_ is not one of *"fractional"*, *"numeric"* or *"2-digit"*, throw a *RangeError* exception.
666+
1. Return ~unused~.
667+
</emu-alg>
668+
</emu-clause>
663669
</emu-clause>
664670

665671
<emu-clause id="sec-computefractionaldigits" oldids="sec-addfractionaldigits" type="abstract operation">

0 commit comments

Comments
 (0)