Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Define date-time options used for date-range formatting as part of the date-range patterns. #25

Merged
merged 3 commits into from
Jan 16, 2021

Conversation

fabalbon
Copy link
Member

Fixes #21.

spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated
<li><ins>{[[Source]]: `"startRange"`, [[Pattern]]: `"{day}/{month}/{year}, {hour}:{minute}"`}</ins></li>
<li><ins>{[[Source]]: `"shared"`, [[Pattern]]: `" – "`}</ins></li>
<li><ins>{[[Source]]: `"endRange"`, [[Pattern]]: `"{hour}:{minute}"`}</ins></li>
<li><ins>[[year]]: `"2-digit"`</ins></li>
Copy link

Choose a reason for hiding this comment

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

The field names should be in upper-case, because

  1. The description says they have the names of the internal slot names from http://tc39.es/proposal-intl-DateTimeFormat-formatRange/#table-datetimeformat-components, which are in upper-case.
  2. The modified http://tc39.es/proposal-intl-DateTimeFormat-formatRange/#sec-formatdatetimepattern algorithm also uses the internal slot names from http://tc39.es/proposal-intl-DateTimeFormat-formatRange/#table-datetimeformat-components.

If you want to use lower-case names for consistency with the existing format descriptions, you need to refer to the "Property" column instead of the "Internal Slot" column. But also see tc39/ecma402#81 and tc39/ecma402#339.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting, I wasn't aware of tc39/ecma402#81 and tc39/ecma402#339.

I prefer to keep it lower-case for the moment because updating it would require several updates in 1.1.1 InitializeDateTimeFormat (e.g. Line 28) as well as some parts in 1.3.3 Internal Slots, and I would prefer to minimize the number of changes unrelated to this proposal in order to keep the proposal's PR focused. But I totally agree that we should work on this on a follow-up spec fix.

Given this, I updated the 1.1.6 FormatDateTimePattern and 1.1.10 PartitionDateTimeRangePattern to reference to the property column instead. PTAL

spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated
@@ -294,7 +294,8 @@ contributors: Google, Ecma International
1. Add new part record { [[Type]]: `"literal"`, [[Value]]: _literal_ } as a new element of the list _result_.
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. <ins>If _rangeFormatOptions_ is not *undefined*, let _f_ be the value of _rangeFormatOptions_'s field whose name is the Internal Slot column of the matching row.</ins>
Copy link

Choose a reason for hiding this comment

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

(Why doesn't GH allow me to annotate a line which wasn't modified in this PR? Sigh.)

Later one there's a step containing:

If p is "month", then the String value may also depend on whether dateTimeFormat has a [[Day]] internal slot. If p is "timeZoneName", then the String value may also depend on the value of the [[inDST]] field of tm. If p is "era", then the String value may also depend on whether dateTimeFormat has a [[Era]] internal slot and if the implementation does not have a localized representation of f, then use f itself.

Let's ignore that "has a [[Day]] internal slot" is a bug in ECMA-402 (internal slots are always present; this should instead check that the internal slot's value isn't undefined). That part probably now needs to include the case when rangeFormatOptions is used instead of dateTimeFormat.

(Hmm, I don't understand the "era" handling in that step. Specifically, "if the implementation does not have a localized representation of f, then use f itself", but f is one of "narrow", "short", or "long". And I'm pretty sure these strings shouldn't appear verbatim in the output...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing this out! I had missed this. I updated this paragraph to account for rangeFormatOptions, PTAL.

Let's ignore that "has a [[Day]] internal slot" is a bug in ECMA-402 (internal slots are always present; this should instead check that the internal slot's value isn't undefined).

I updated this instance of this error.

(Hmm, I don't understand the "era" handling in that step. Specifically, "if the implementation does not have a localized representation of f, then use f itself", but f is one of "narrow", "short", or "long". And I'm pretty sure these strings shouldn't appear verbatim in the output...)

This sounds like a bug in the the spec, you are right that the value of f is not suitable (and doesn't make sense) for the output. I'll file a bug for this.

spec.emu Outdated Show resolved Hide resolved
fabalbon added a commit that referenced this pull request Oct 5, 2020
…e date-range patterns (Issue #21).

Together with this, update FormatDateTimePattern to use these options instead of the default options used by date-time formatting.
@fabalbon
Copy link
Member Author

fabalbon commented Jan 9, 2021

I rebased latest changes in in the main branch. @anba PTAL, I'll merge this PR as soon as you LGTM. Thanks!

Copy link
Member

@leobalter leobalter left a comment

Choose a reason for hiding this comment

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

There is small nitpick (a missing ,) and a last rebase missing, otherwise LGTM

spec.emu Outdated Show resolved Hide resolved
Co-authored-by: Leo Balter <[email protected]>
@fabalbon fabalbon merged commit 81d7b38 into master Jan 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PartitionDateTimeRangePattern may need additional date-time fields not present in the formatter
4 participants