Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions spec/datetimeformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ <h1>Abstract Operations For DateTimeFormat Objects</h1>
<td>`"year"`</td>
<td>`"2-digit"`, `"numeric"`</td>
</tr>
<tr>
<td>[[Quarter]]</td>
<td>`"quarter"`</td>
<td>`"narrow"`, `"short"`, `"long"`</td>
</tr>
<tr>
<td>[[Month]]</td>
<td>`"month"`</td>
Expand Down Expand Up @@ -159,7 +164,7 @@ <h1>ToDateTimeOptions ( _options_, _required_, _defaults_ )</h1>
1. Let _options_ be ObjectCreate(_options_).
1. Let _needDefaults_ be *true*.
1. If _required_ is `"date"` or `"any"`, then
1. For each of the property names `"weekday"`, `"year"`, `"month"`, `"day"`, do
1. For each of the property names `"weekday"`, `"year"`, `"quarter"`, `"month"`, `"day"`, do
1. Let _prop_ be the property name.
1. Let _value_ be ? Get(_options_, _prop_).
1. If _value_ is not *undefined*, let _needDefaults_ be *false*.
Expand Down Expand Up @@ -281,7 +286,10 @@ <h1>PartitionDateTimePattern ( _dateTimeFormat_, _x_ )</h1>
1. Let _p_ be the substring of _pattern_ from position _beginIndex_, exclusive, to position _endIndex_, exclusive.
1. If _p_ matches a Property column of the row in <emu-xref href="#table-datetimeformat-components"></emu-xref>, then
1. Let _f_ be the value of _dateTimeFormat_'s internal slot whose name is the Internal Slot column of the matching row.
1. Let _v_ be the value of _tm_'s field whose name is the Internal Slot column of the matching row.
1. If _p_ is `"quarter"`, then
1. Let _v_ be ( _tm_.[[month]] / 3 ) + 1.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assumes only 12 months

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, it assume every 3 months is a quarter and won't prevent month 13 to be 5th quarter in the calendar have more than 12 months.

Also according to
https://www.ecma-international.org/ecma-262/9.0/index.html#sec-month-number
"Months are identified by an integer in the range 0 to 11, inclusive."

The ICU logic is in i18n/smpdtfmt.cpp

    case UDAT_QUARTER_FIELD:
        if (count >= 4)
            _appendSymbol(appendTo, value/3, fSymbols->fQuarters,
                          fSymbols->fQuartersCount);
        else if (count == 3)
            _appendSymbol(appendTo, value/3, fSymbols->fShortQuarters,
                          fSymbols->fShortQuartersCount);
        else
            zeroPaddingNumber(currentNumberFormat,appendTo, (value/3) + 1, count, maxIntCount);
        break;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quarter means a fourth of something. So a 5th quarter is not a quarter.

20.3.1.4 Month Number is also wrong for non-Gregorian calendars, then. because 0 to 11 inclusive is not sufficient. Perhaps you should spec this just for gregorian calendars?

Note my node (v8) example referenced above showing numeric formats from 1 to 13 inclusive: https://gist.github.com/srl295/4ce6860667770b5cf563c383897d1b20

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the ICU logic for Java for quarter is broken for the Hebrew calendar, it produces garbage output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Ecma262 reference above binding on Ecma402 date formats? I wouldn't think so, otherwise non-12 month calendars would not be supported at all.

1. Else,
1. Let _v_ be the value of _tm_'s field whose name is the Internal Slot column of the matching row.
1. If _p_ is `"year"` and _v_ ≤ 0, let _v_ be 1 - _v_.
1. If _p_ is `"month"`, increase _v_ by 1.
1. If _p_ is `"hour"` and _dateTimeFormat_.[[HourCycle]] is `"h11"` or `"h12"`, then
Expand Down Expand Up @@ -421,7 +429,7 @@ <h1>Intl.DateTimeFormat ( [ _locales_ [ , _options_ ] ] )</h1>

<emu-alg>
1. If NewTarget is *undefined*, let _newTarget_ be the active function object, else let _newTarget_ be NewTarget.
1. Let _dateTimeFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, `"%DateTimeFormatPrototype%"`, &laquo; [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[HourCycle]], [[Pattern]], [[BoundFormat]] &raquo;).
1. Let _dateTimeFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, `"%DateTimeFormatPrototype%"`, &laquo; [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Quarter]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[HourCycle]], [[Pattern]], [[BoundFormat]] &raquo;).
1. Perform ? InitializeDateTimeFormat(_dateTimeFormat_, _locales_, _options_).
</emu-alg>
<emu-normative-optional>
Expand Down Expand Up @@ -509,6 +517,7 @@ <h1>Internal slots</h1>
<ul>
<li>weekday, year, month, day, hour, minute, second</li>
<li>weekday, year, month, day</li>
<li>year, quarter</li>
<li>year, month, day</li>
<li>year, month</li>
<li>month, day</li>
Expand Down Expand Up @@ -670,6 +679,10 @@ <h1>Intl.DateTimeFormat.prototype.resolvedOptions ()</h1>
<td>[[Year]]</td>
<td>`"year"`</td>
</tr>
<tr>
<td>[[Quarter]]</td>
<td>`"quarter"`</td>
</tr>
<tr>
<td>[[Month]]</td>
<td>`"month"`</td>
Expand Down Expand Up @@ -731,7 +744,7 @@ <h1>Properties of Intl.DateTimeFormat Instances</h1>
<li>[[Calendar]] is a String value with the `"type"` given in Unicode Technical Standard 35 for the calendar used for formatting.</li>
<li>[[NumberingSystem]] is a String value with the `"type"` given in Unicode Technical Standard 35 for the numbering system used for formatting.</li>
<li>[[TimeZone]] is a String value with the IANA time zone name of the time zone used for formatting.</li>
<li>[[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]] are each either *undefined*, indicating that the component is not used for formatting, or one of the String values given in <emu-xref href="#table-datetimeformat-components"></emu-xref>, indicating how the component should be presented in the formatted output.</li>
<li>[[Weekday]], [[Era]], [[Year]], [[Quarter]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]] are each either *undefined*, indicating that the component is not used for formatting, or one of the String values given in <emu-xref href="#table-datetimeformat-components"></emu-xref>, indicating how the component should be presented in the formatted output.</li>
<li>[[HourCycle]] is a String value indicating whether the 12-hour format (`"h11"`, `"h12"`) or the 24-hour format (`"h23"`, `"h24"`) should be used. `"h11"` and `"h23"` start with hour 0 and go up to 11 and 23 respectively. `"h12"` and `"h24"` start with hour 1 and go up to 12 and 24. [[HourCycle]] is only used when [[Hour]] is not *undefined*.</li>
<li>[[Pattern]] is a String value as described in <emu-xref href="#sec-intl.datetimeformat-internal-slots"></emu-xref>.</li>
</ul>
Expand Down