Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and simplify "displayRequired" computation in PartitionDurationFormatPattern #183

Closed
wants to merge 3 commits into from

Conversation

anba
Copy link
Contributor

@anba anba commented Jan 8, 2024

Fixes:

  • durationFormat.[[SecondsValue]] should be duration.[[Seconds]]
  • Sub-second fields were incorrectly ignored

Simplications:

  • Change displayRequired to a boolean.
  • durationFormat.[[HoursStyle]], durationFormat.[[HoursDisplay]], and duration.[[Hours]] don't have to be inspected, instead simply testing if needSeparator is true is sufficient.
  • needSeparator doesn't need to be reset. This step was only present for compatibility with previous revisions to output strings like 1, 03 for {hours: 1, seconds: 3} (see hours: "numeric" w/ 0 in minutes and non 0 in seconds cause strange output. #170).

If `durationFormat.[[HoursStyle]]` is "numeric" or "2-digit" and either
`durationFormat.[[HoursDisplay]]` is "always" or `duration.[[Hours]]` is
non-zero, then the previous loop iteration set `needSeparator` to `true`.

Drive-by change: Use booleans for `displayRequired`.
To determine if the minutes field should always be formatted, we need to inspect
all sub-minutes duration fields.
`needSeparator` only needed to be reset to output `"2, 01"`.
anba added a commit to anba/test262 that referenced this pull request Jan 9, 2024
Sync `partitionDurationFormatPattern` with the latest spec draft and
change it to use an `Intl.DurationFormat` object as the input, so it's
easier to compare it against the spec text and because it allows to test
more inputs.

Includes the fixes for:
- tc39/proposal-intl-duration-format#183
- tc39/proposal-intl-duration-format#184
Copy link
Member

@ryzokuken ryzokuken left a comment

Choose a reason for hiding this comment

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

LGTM overall, is this normative or a bugfix? I lean towards the latter but would love to hear your thoughts @anba @sffc @FrankYFTang

@anba
Copy link
Contributor Author

anba commented Jan 11, 2024

e717eb2 and 91f2eb0 are purely editorial. 6b4a0b3 is a bug fix for #180.

@FrankYFTang
Copy link
Collaborator

yes, I think this PR is better.

@ben-allen
Copy link
Collaborator

lgtm! note that these errors are (unless I'm mistaken) also fixed in #188, which is waiting for review/re-review

@ben-allen ben-allen self-assigned this Apr 17, 2024
@ben-allen ben-allen self-requested a review April 17, 2024 17:52
Copy link
Collaborator

@ben-allen ben-allen left a comment

Choose a reason for hiding this comment

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

good catches all -- thanks for finding that error with subsecond unit displays

Ms2ger pushed a commit to anba/test262 that referenced this pull request Apr 23, 2024
Sync `partitionDurationFormatPattern` with the latest spec draft and
change it to use an `Intl.DurationFormat` object as the input, so it's
easier to compare it against the spec text and because it allows to test
more inputs.

Includes the fixes for:
- tc39/proposal-intl-duration-format#183
- tc39/proposal-intl-duration-format#184
Ms2ger pushed a commit to tc39/test262 that referenced this pull request Apr 23, 2024
Sync `partitionDurationFormatPattern` with the latest spec draft and
change it to use an `Intl.DurationFormat` object as the input, so it's
easier to compare it against the spec text and because it allows to test
more inputs.

Includes the fixes for:
- tc39/proposal-intl-duration-format#183
- tc39/proposal-intl-duration-format#184
@ben-allen
Copy link
Collaborator

closed as fixed by #188

@ben-allen ben-allen closed this Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants