Skip to content

Commit cb2e0ff

Browse files
ptomatoMs2ger
authored andcommitted
Editorial: Use ISO Date Records in ToISOWeekOfYear/DayOfYear/DayOfWeek
Instead of passing each component individually. Also, remove the "To" from the name, as it's not a conversion operation. See: #2949
1 parent dd9679f commit cb2e0ff

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

spec/calendar.html

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ <h1>Calendar Date Records</h1>
135135
<p>The Year-Week Record's [[Year]] field is relative to the first day of a calendar-specific "epoch year", as in the Calendar Date Record's [[Year]] field, not relative to an era as in [[EraYear]].</p>
136136
<p>
137137
Usually the Year-Week Record's [[Year]] field will contain the same value as the Calendar Date Record's [[Year]] field, but may contain the previous or next year if the week number in the Year-Week Record's [[Week]] field overlaps two different years.
138-
See also ToISOWeekOfYear.
138+
See also ISOWeekOfYear.
139139
</p>
140140
<p>The Year-Week Record contains *undefined* in [[Week]] and [[Year]] field for calendars that do not have a well-defined week calendar system.</p>
141141
<emu-note type="editor">
@@ -667,32 +667,31 @@ <h1>
667667
</emu-alg>
668668
</emu-clause>
669669

670-
<emu-clause id="sec-temporal-toisoweekofyear" type="abstract operation">
670+
<emu-clause id="sec-temporal-isoweekofyear" type="abstract operation">
671671
<h1>
672-
ToISOWeekOfYear (
673-
_year_: an integer,
674-
_month_: an integer,
675-
_day_: an integer,
672+
ISOWeekOfYear (
673+
_isoDate_: an ISO Date Record,
676674
): a Year-Week Record
677675
</h1>
678676
<dl class="header">
679677
<dt>description</dt>
680678
<dd>It determines where a calendar day falls in the ISO 8601 week calendar and calculates its <em>calendar week of year</em>, which is the 1-based ordinal number of its calendar week within the corresponding <em>week calendar year</em> (which may differ from _year_ by up to 1 in either direction).</dd>
681679
</dl>
682680
<emu-alg>
683-
1. Assert: IsValidISODate(_year_, _month_, _day_) is *true*.
681+
1. Let _year_ be _isoDate_.[[Year]].
684682
1. Let _wednesday_ be 3.
685683
1. Let _thursday_ be 4.
686684
1. Let _friday_ be 5.
687685
1. Let _saturday_ be 6.
688686
1. Let _daysInWeek_ be 7.
689687
1. Let _maxWeekNumber_ be 53.
690-
1. Let _dayOfYear_ be ToISODayOfYear(_year_, _month_, _day_).
691-
1. Let _dayOfWeek_ be ToISODayOfWeek(_year_, _month_, _day_).
692-
1. Let _week_ be floor((_dayOfYear_ + _daysInWeek_ - _dayOfWeek_ + _wednesday_ ) / _daysInWeek_).
688+
1. Let _dayOfYear_ be ISODayOfYear(_isoDate_).
689+
1. Let _dayOfWeek_ be ISODayOfWeek(_isoDate_).
690+
1. Let _week_ be floor((_dayOfYear_ + _daysInWeek_ - _dayOfWeek_ + _wednesday_) / _daysInWeek_).
693691
1. If _week_ &lt; 1, then
694692
1. NOTE: This is the last week of the previous year.
695-
1. Let _dayOfJan1st_ be ToISODayOfWeek(_year_, 1, 1).
693+
1. Let _jan1st_ be CreateISODateRecord(_year_, 1, 1).
694+
1. Let _dayOfJan1st_ be ISODayOfWeek(_jan1st_).
696695
1. If _dayOfJan1st_ = _friday_, then
697696
1. Return Year-Week Record { [[Week]]: _maxWeekNumber_, [[Year]]: _year_ - 1 }.
698697
1. If _dayOfJan1st_ = _saturday_, and MathematicalInLeapYear(EpochTimeForYear(_year_ - 1)) = 1, then
@@ -710,40 +709,34 @@ <h1>
710709
<emu-note>For example, week calendar year 2020 includes both 31 December 2019 (a Tuesday belonging to its calendar week 1) and 1 January 2021 (a Friday belonging to its calendar week 53).</emu-note>
711710
</emu-clause>
712711

713-
<emu-clause id="sec-temporal-toisodayofyear" type="abstract operation">
712+
<emu-clause id="sec-temporal-isodayofyear" type="abstract operation">
714713
<h1>
715-
ToISODayOfYear (
716-
_year_: an integer,
717-
_month_: an integer,
718-
_day_: an integer,
714+
ISODayOfYear (
715+
_isoDate_: an ISO Date Record,
719716
): an integer
720717
</h1>
721718
<dl class="header">
722719
<dt>description</dt>
723720
<dd>It returns the ISO 8601 <em>calendar day of year</em> of a calendar day, which is its 1-based ordinal number within its ISO 8601 calendar year.</dd>
724721
</dl>
725722
<emu-alg>
726-
1. Assert: IsValidISODate(_year_, _month_, _day_) is *true*.
727-
1. Let _epochDays_ be ISODateToEpochDays(_year_, _month_ - 1, _day_).
723+
1. Let _epochDays_ be ISODateToEpochDays(_isoDate_.[[Year]], _isoDate_.[[Month]] - 1, _isoDate_.[[Day]]).
728724
1. Return EpochTimeToDayInYear(EpochDaysToEpochMs(_epochDays_, 0)) + 1.
729725
</emu-alg>
730726
</emu-clause>
731727

732-
<emu-clause id="sec-temporal-toisodayofweek" type="abstract operation">
728+
<emu-clause id="sec-temporal-isodayofweek" type="abstract operation">
733729
<h1>
734-
ToISODayOfWeek (
735-
_year_: an integer,
736-
_month_: an integer,
737-
_day_: an integer,
730+
ISODayOfWeek (
731+
_isoDate_: an ISO Date Record,
738732
): an integer
739733
</h1>
740734
<dl class="header">
741735
<dt>description</dt>
742736
<dd>It returns the ISO 8601 <em>calendar day of week</em> of a calendar day, which is its 1-based ordinal position within the sequence of week calendar days that starts with Monday at 1 and ends with Sunday at 7.</dd>
743737
</dl>
744738
<emu-alg>
745-
1. Assert: IsValidISODate(_year_, _month_, _day_) is *true*.
746-
1. Let _epochDays_ be ISODateToEpochDays(_year_, _month_ - 1, _day_).
739+
1. Let _epochDays_ be ISODateToEpochDays(_isoDate_.[[Year]], _isoDate_.[[Month]] - 1, _isoDate_.[[Day]]).
747740
1. Let _dayOfWeek_ be EpochTimeToWeekDay(EpochDaysToEpochMs(_epochDays_, 0)).
748741
1. If _dayOfWeek_ = 0, return 7.
749742
1. Return _dayOfWeek_.
@@ -847,9 +840,9 @@ <h1>
847840
[[Month]]: _isoDate_.[[Month]],
848841
[[MonthCode]]: _monthCode_,
849842
[[Day]]: _isoDate_.[[Day]],
850-
[[DayOfWeek]]: ToISODayOfWeek(_isoDate_.[[Year]], _isoDate_.[[Month]], _isoDate_.[[Day]]),
851-
[[DayOfYear]]: ToISODayOfYear(_isoDate_.[[Year]], _isoDate_.[[Month]], _isoDate_.[[Day]]),
852-
[[WeekOfYear]]: ToISOWeekOfYear(_isoDate_.[[Year]], _isoDate_.[[Month]], _isoDate_.[[Day]]),
843+
[[DayOfWeek]]: ISODayOfWeek(_isoDate_),
844+
[[DayOfYear]]: ISODayOfYear(_isoDate_),
845+
[[WeekOfYear]]: ISOWeekOfYear(_isoDate_),
853846
[[DaysInWeek]]: 7,
854847
[[DaysInMonth]]: ISODaysInMonth(_isoDate_.[[Year]], _isoDate_.[[Month]]),
855848
[[DaysInYear]]: MathematicalDaysInYear(_isoDate_.[[Year]]),

spec/mainadditions.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h1><a href="https://tc39.es/ecma262/#sec-ecmascript-language-types-string-type"
3333
<emu-clause id="sec-year-week-record-specification-type">
3434
<h1>The Year-Week Record Specification Type</h1>
3535
<p>
36-
The <dfn variants="Year-Week Records">Year-Week Record</dfn> specification type is returned by the week number calculation in ToISOWeekOfYear, and the corresponding calculations for other calendars if applicable.
36+
The <dfn variants="Year-Week Records">Year-Week Record</dfn> specification type is returned by the week number calculation in ISOWeekOfYear, and the corresponding calculations for other calendars if applicable.
3737
It comprises a <em>calendar week of year</em> with the corresponding <em>week calendar year</em>.
3838
</p>
3939
<p>Year-Week Records have the fields listed in table <emu-xref href="#table-year-week-record"></emu-xref>.</p>

0 commit comments

Comments
 (0)