Skip to content

Commit

Permalink
Editorial: Refactor calendar formatting operations
Browse files Browse the repository at this point in the history
The repeated normative change in the previous commit goes into its own
abstract operation, MaybeFormatCalendarAnnotation.
While we are at it, updates FormatCalendarAnnotation to use a structured
header, and updates the link in the editor's note.
  • Loading branch information
ptomato committed Aug 2, 2022
1 parent 496afbb commit aaa85d1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
48 changes: 40 additions & 8 deletions spec/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -389,21 +389,53 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-formatcalendarannotation" aoid="FormatCalendarAnnotation">
<h1>FormatCalendarAnnotation ( _id_, _showCalendar_ )</h1>
<p>
The abstract operation FormatCalendarAnnotation returns a string with a calendar annotation suitable for concatenating to the end of an ISO 8601 string.
Depending on the given _id_ and value of _showCalendar_, the string may be empty if no calendar annotation need be included.
</p>
<emu-clause id="sec-temporal-maybeformatcalendarannotation" type="abstract operation">
<h1>
MaybeFormatCalendarAnnotation (
_calendarObject_: an Object,
_showCalendar_: one of *"auto"*, *"always"*, or *"never"*,
): either a normal completion containing a String, or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>
It returns a string with a calendar annotation suitable for concatenating to the end of an ISO 8601 string.
Depending on the given _calendarObject_ and the value of _showCalendar_, the string may be empty if no calendar annotation need be included.
This operation may invoke an observable ToString operation on _calendarObject_, but not if _showCalendar_ is *"never"*.
</dd>
</dl>
<emu-alg>
1. If _showCalendar_ is *"never"*, return the empty String.
1. Let _calendarID_ be ? ToString(_calendarObject_).
1. Return FormatCalendarAnnotation(_calendarID_, _showCalendar_).
</emu-alg>
<emu-note type="editor">
The exact form this annotation will take is undergoing a standardization process in the IETF; it is being discussed in the Internet Draft <a href="https://ryzokuken.dev/draft-ryzokuken-datetime-extended/documents/rfc-3339.html#name-internet-date-time-format">Date and Time on the Internet: Timestamps with additional information</a>.
The exact form this annotation will take is undergoing a standardization process in the IETF; it is being discussed in the Internet Draft <a href="https://datatracker.ietf.org/doc/html/draft-ietf-sedate-datetime-extended">Date and Time on the Internet: Timestamps with additional information</a>.
</emu-note>
</emu-clause>

<emu-clause id="sec-temporal-formatcalendarannotation" type="abstract operation">
<h1>
FormatCalendarAnnotation (
_id_: a String,
_showCalendar_: one of *"auto"*, *"always"*, or *"never"*,
): a String
</h1>
<dl class="header">
<dt>description</dt>
<dd>
It returns a string with a calendar annotation suitable for concatenating to the end of an ISO 8601 string.
Depending on the given _id_ and value of _showCalendar_, the string may be empty if no calendar annotation need be included.
</dd>
</dl>
<emu-alg>
1. Assert: _showCalendar_ is *"auto"*, *"always"*, or *"never"*.
1. If _showCalendar_ is *"never"*, return the empty String.
1. If _showCalendar_ is *"auto"* and _id_ is *"iso8601"*, return the empty String.
1. Return the string-concatenation of *"[u-ca="*, _id_, and *"]"*.
</emu-alg>
<emu-note type="editor">
The exact form this annotation will take is undergoing a standardization process in the IETF; it is being discussed in the Internet Draft <a href="https://datatracker.ietf.org/doc/html/draft-ietf-sedate-datetime-extended">Date and Time on the Internet: Timestamps with additional information</a>.
</emu-note>
</emu-clause>

<emu-clause id="sec-temporal-calendarequals" aoid="CalendarEquals">
Expand Down
6 changes: 1 addition & 5 deletions spec/plaindate.html
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,7 @@ <h1>TemporalDateToString ( _temporalDate_, _showCalendar_ )</h1>
1. Let _year_ be ! PadISOYear(_temporalDate_.[[ISOYear]]).
1. Let _month_ be ToZeroPaddedDecimalString(_temporalDate_.[[ISOMonth]], 2).
1. Let _day_ be ToZeroPaddedDecimalString(_temporalDate_.[[ISODay]], 2).
1. If _showCalendar_ is *"never"*, then
1. Let _calendar_ be the empty String.
1. Else,
1. Let _calendarID_ be ? ToString(_temporalDate_.[[Calendar]]).
1. Let _calendar_ be ! FormatCalendarAnnotation(_calendarID_, _showCalendar_).
1. Let _calendar_ be ? MaybeFormatCalendarAnnotation(_temporalDate_.[[Calendar]], _showCalendar_).
1. Return the string-concatenation of _year_, the code unit 0x002D (HYPHEN-MINUS), _month_, the code unit 0x002D (HYPHEN-MINUS), _day_, and _calendar_.
</emu-alg>
</emu-clause>
Expand Down
6 changes: 1 addition & 5 deletions spec/plaindatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -964,11 +964,7 @@ <h1>TemporalDateTimeToString ( _isoYear_, _isoMonth_, _isoDay_, _hour_, _minute_
1. Let _hour_ be ToZeroPaddedDecimalString(_hour_, 2).
1. Let _minute_ be ToZeroPaddedDecimalString(_minute_, 2).
1. Let _seconds_ be ! FormatSecondsStringPart(_second_, _millisecond_, _microsecond_, _nanosecond_, _precision_).
1. If _showCalendar_ is *"never"*, then
1. Let _calendarString_ be the empty String.
1. Else,
1. Let _calendarID_ be ? ToString(_calendar_).
1. Let _calendarString_ be ! FormatCalendarAnnotation(_calendarID_, _showCalendar_).
1. Let _calendarString_ be ? MaybeFormatCalendarAnnotation(_calendar_, _showCalendar_).
1. Return the string-concatenation of _year_, the code unit 0x002D (HYPHEN-MINUS), _month_, the code unit 0x002D (HYPHEN-MINUS), _day_, 0x0054 (LATIN CAPITAL LETTER T), _hour_, the code unit 0x003A (COLON), _minute_, _seconds_, and _calendarString_.
</emu-alg>
</emu-clause>
Expand Down
2 changes: 1 addition & 1 deletion spec/plainmonthday.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ <h1>TemporalMonthDayToString ( _monthDay_, _showCalendar_ )</h1>
1. If _showCalendar_ is *"always"* or if _calendarID_ is not *"iso8601"*, then
1. Let _year_ be ! PadISOYear(_monthDay_.[[ISOYear]]).
1. Set _result_ to the string-concatenation of _year_, the code unit 0x002D (HYPHEN-MINUS), and _result_.
1. Let _calendarString_ be ! FormatCalendarAnnotation(_calendarID_, _showCalendar_).
1. Let _calendarString_ be FormatCalendarAnnotation(_calendarID_, _showCalendar_).
1. Set _result_ to the string-concatenation of _result_ and _calendarString_.
1. Return _result_.
</emu-alg>
Expand Down
2 changes: 1 addition & 1 deletion spec/plainyearmonth.html
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ <h1>TemporalYearMonthToString ( _yearMonth_, _showCalendar_ )</h1>
1. If _showCalendar_ is *"always"* or if _calendarID_ is not *"iso8601"*, then
1. Let _day_ be ToZeroPaddedDecimalString(_yearMonth_.[[ISODay]], 2).
1. Set _result_ to the string-concatenation of _result_, the code unit 0x002D (HYPHEN-MINUS), and _day_.
1. Let _calendarString_ be ! FormatCalendarAnnotation(_calendarID_, _showCalendar_).
1. Let _calendarString_ be FormatCalendarAnnotation(_calendarID_, _showCalendar_).
1. Set _result_ to the string-concatenation of _result_ and _calendarString_.
1. Return _result_.
</emu-alg>
Expand Down
6 changes: 1 addition & 5 deletions spec/zoneddatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -1196,11 +1196,7 @@ <h1>
1. Else,
1. Let _timeZoneID_ be ? ToString(_timeZone_).
1. Let _timeZoneString_ be the string-concatenation of the code unit 0x005B (LEFT SQUARE BRACKET), _timeZoneID_, and the code unit 0x005D (RIGHT SQUARE BRACKET).
1. If _showCalendar_ is *"never"*, then
1. Let _calendarString_ be the empty String.
1. Else,
1. Let _calendarID_ be ? ToString(_zonedDateTime_.[[Calendar]]).
1. Let _calendarString_ be ! FormatCalendarAnnotation(_calendarID_, _showCalendar_).
1. Let _calendarString_ be ? MaybeFormatCalendarAnnotation(_zonedDateTime_.[[Calendar]], _showCalendar_).
1. Return the string-concatenation of _dateTimeString_, _offsetString_, _timeZoneString_, and _calendarString_.
</emu-alg>
</emu-clause>
Expand Down

0 comments on commit aaa85d1

Please sign in to comment.