tc39 / proposal-intl-locale-info

An API to expose information of locale, such as week data ( first day of a week, weekend start, weekend end), hour cycle, measurement system, commonly used calendar, etc.
MIT License
56 stars 11 forks source link

Add support for -u-fw and other Unicode extensions that could impact the result #68

Closed sffc closed 3 months ago

sffc commented 1 year ago

Related: #30, https://github.com/tc39/ecma402/issues/580

If I write

new Intl.Locale("en-u-fw-tue").getWeekInfo()

then I should get that the first day is Tuesday, but it currently ignores the -u-fw.

FrankYFTang commented 1 year ago

This issue, if put into the proposal, would mean we also have to

  1. add additional getter "get Intl.Locale.prototype.firstDayOfWeek"
  2. in https://tc39.es/ecma402/#sec-intl.locale-internal-slots add "fw" into "The value of the [[RelevantExtensionKeys]]"
  3. in Intl.Locale ( tag [ , options ] ) we need to add step to read "firstDayOfWeek" from option and validate the value.
sffc commented 1 year ago

TG2 agreement: https://github.com/tc39/ecma402/blob/master/meetings/notes-2023-05-04.md#add-support-for--u-fw-and-other-unicode-extensions-that-could-impact-the-result

Would like to see this as a normative PR in the July TG1 meeting.

anba commented 1 year ago

If I write

new Intl.Locale("en-u-fw-tue").getWeekInfo()

then I should get that the first day is Tuesday, but it currently ignores the -u-fw.

IIRC you actually get Tuesday starting with ICU 73 (ICU-22226), assuming the input locale is passed as-is to ICU. Addressing #30 should help to clarify how Unicode extension tags are handled.

FrankYFTang commented 1 year ago

So I will add a new getter

1.4.X get Intl.Locale.prototype.firstDayOfWeek

that will return one of the 7 possible values "sun", "mon", "tue", "wed", "thu", "fri", "sat"

FrankYFTang commented 1 year ago

I think this request surface yet another problem in our current spec Currently the return value of Intl.Locale.prototype.getWeekInfo ( ) use integer 1-7 to represent the weekday as specified in https://tc39.es/proposal-intl-locale-info/#sec-week-info-of-locale

in the firstDay field as a single value and in the weekend as an array (usually 2 values)

But since we are now need to add a getter firstDayOfWeek to return string <<"sun", "mon", "tue", "wed", "thu", "fri", "sat">> should we also change the getWeekInfo().firstDay to reutrn one of <<"sun", "mon", "tue", "wed", "thu", "fri", "sat">> and getWeekInfo().weekend to return an arry of string in <<"sun", "mon", "tue", "wed", "thu", "fri", "sat">> instead?

sffc commented 1 year ago

TG2 discussion: https://github.com/tc39/ecma402/blob/master/meetings/notes-2023-06-29.md#intllocale-info-discussion

FrankYFTang commented 1 year ago

This issue and https://github.com/tc39/proposal-intl-locale-info/pull/70 was presented to TC39 in July 12, 2023 meeting and does NOT reach consensus for the proposed changes.

Here are my understanding of the part which reach consensus: a. No objection of the need to add "fw" to the [[RelevantExtensionKeys]] internal slots in Intl.Locale in order to read "-u-fw-" from the locale identifier. b. No objection of adding the [[FirstDayOfWeek]] to internal slots in Intl.Locale to keep track the information from a. c. No objection that the getWeekInfo().firstDay will depends on the value in the [[FirstDayOfWeek]] to internal slots in Intl.Locale d. No objection to keep the getWeekInfo().firstDay value in the range 1..7 to sync with Temporal. e. No objection of the need to add a option reading step to get the information to [[FirstDayOfWeek]] in addition to the parsed result from a. e. No objection of the property name to be read from the option as "firstDayOfWeek". f. No objection of adding a getter Intl.Locale.prototype.firstDayOfWeek .

But there are disagreement during July 12 TC39 about I. What should be the possible values that Intl.Locale.prototype.firstDayOfWeek could return. II What should be the possible values that the option reading of firstDayOfWeek proper should accept.

Option A (as in the current state (July 11, 2023) of PR70)

I. Intl.Locale.prototype.firstDayOfWeek returns: <<undefined, "mon", "tue", "wed", "thu", "fri", "sat", "sun">>

  1. {firstDayOfWeek} for new Intl.Locale() accepts: <<undefined, "mon", "tue", "wed", "thu", "fri", "sat", "sun">> Default: undefined

Option B (as mentioned in the TC39)

I. Intl.Locale.prototype.firstDayOfWeek returns: <<undefined, 1, 2, 3, 4, 5, 6, 7>>

  1. {firstDayOfWeek} for new Intl.Locale() accepts: <<undefined, "mon", "tue", "wed", "thu", "fri", "sat", "sun", 1, 2, 3, 4, 5, 6, 7>> Default: undefined

Option C (Also mentioned in the TC39)

I. Intl.Locale.prototype.firstDayOfWeek returns: <<undefined, 1, 2, 3, 4, 5, 6, 7>>

  1. {firstDayOfWeek} for new Intl.Locale() accepts: <<undefined, "mon", "tue", "wed", "thu", "fri", "sat", "sun", 0, 1, 2, 3, 4, 5, 6, 7>> Default: undefined where 0, 7, "sun" all repesent Sunday in option reading

Option D

I. Intl.Locale.prototype.firstDayOfWeek returns: <<undefined, 1, 2, 3, 4, 5, 6, 7>>

  1. {firstDayOfWeek} for new Intl.Locale() accepts: <<undefined, 1, 2, 3, 4, 5, 6, 7>> Default: undefined

Option E

I. Intl.Locale.prototype.firstDayOfWeek returns: <<undefined, 1, 2, 3, 4, 5, 6, 7>>

  1. {firstDayOfWeek} for new Intl.Locale() accepts: <<undefined, 0, 1, 2, 3, 4, 5, 6, 7>> Default: undefined where 0, and 7 both repesent Sunday in option reading

Option C and Option E consider the fact that Date.prototype.getDay ( ) return 0, but not 7, for Sunday. See https://tc39.es/ecma262/#sec-date.prototype.getday

FrankYFTang commented 1 year ago

Most people after TG2 2023-09-07 meeting unofficially support Option C

sffc commented 1 year ago

TG2 notes: https://github.com/tc39/ecma402/blob/master/meetings/notes-2023-09-07.md#add-support-for--u-fw-and-other-unicode-extensions-that-could-impact-the-result-68

FrankYFTang commented 11 months ago

This issue is addressed by PR70 after TC39 on 2023-09 which is option C. However, it cause issue in https://github.com/tc39/proposal-intl-locale-info/issues/78 and we now plan to revert from option C

I plan to change the spect to the following: I. Intl.Locale.prototype.firstDayOfWeek returns: <<undefined, "mon", "tue", "wed", "thu", "fri", "sat", "sun">>

  1. {firstDayOfWeek} for new Intl.Locale() accepts: <<undefined, "mon", "tue", "wed", "thu", "fri", "sat", "sun", "0", "1", "2", "3", "4", "5", "6", "7">> Default: undefined where "0", "7", "sun" all repesent Sunday in option reading
FrankYFTang commented 11 months ago

Propose fix in https://github.com/tc39/proposal-intl-locale-info/pull/79

FrankYFTang commented 11 months ago

I. Intl.Locale.prototype.firstDayOfWeek returns: <<undefined, "mon", "tue", "wed", "thu", "fri", "sat", "sun">>

sorry, this is not right. I need to rework on this. Intl.Locale.prototype.firstDayOfWeek need to return string, but not just that 7 string values.

FrankYFTang commented 3 months ago

79 and #82 together should address this issue.