-
Notifications
You must be signed in to change notification settings - Fork 485
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
Update expected results for day period to match CLDR 47 #4428
Open
anba
wants to merge
1
commit into
tc39:main
Choose a base branch
from
anba:day-period-cldr47
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gibson042
approved these changes
Mar 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm approving this as-is, but would really love to see the tests made less brittle, e.g.
var inputs = [];
for (var h = 0; h < 24; h++) {
inputs.push(new Date(2017, 11, 12, h, 0, 0, 0));
}
assert.sameValue(inputs.length, 24);
// Each expected dayPeriod value must be a) contiguous, and
// b) represented in sequence.
var expectedDayPeriods = [
'in the morning',
'noon',
'in the afternoon',
'in the evening',
'at night'
];
var long = new Intl.DateTimeFormat('en', {
dayPeriod: 'long'
});
var longNumeric = new Intl.DateTimeFormat('en', {
dayPeriod: 'long',
hour: 'numeric'
});
var counts = expectedDayPeriods.map(function() { return 0; });
var transitionTargets = [];
var firstDayPeriod, prevDayPeriod;
for (var h = 0; h < 24; h++) {
var dayPeriod = long.format(inputs[h]);
var i = expectedDayPeriods.indexOf(dayPeriod);
assert(i >= 0, 'dayPeriod must be expected: ' + dayPeriod);
if (h === 0) {
firstDayPeriod = dayPeriod;
transitionTargets.push(dayPeriod);
} else if (dayPeriod !== prevDayPeriod) {
transitionTargets.push(dayPeriod);
var oldCount = counts[i];
// The first value might span the beginning and end of a day's hours.
if (dayPeriod !== firstDayPeriod) {
assert.sameValue(oldCount, 0,
'dayPeriod must be contiguous: ' + dayPeriod);
}
}
assert.sameValue(
longNumeric.format(inputs[h]),
// Hour "00" is represented as "12".
((h % 12) || 12) + ' ' + dayPeriod,
'numeric hour must precede dayPeriod');
counts[i]++;
prevDayPeriod = dayPeriod;
}
if (transitionTargets.length > 1) {
if (transitionTargets[transitionTargets.length - 1] === transitionTargets[0]) {
transitionTargets.pop();
}
// Rotate the first expected dayPeriod into initial position.
var i = transitionTargets.indexOf(expectedDayPeriods[0]);
if (i > 0) {
var values = transitionTargets.splice(0, i);
transitionTargets = transitionTargets.concat(values);
}
}
assert.compareArray(transitionTargets, expectedDayPeriods,
'dayPeriods must appear in the right sequence');
@gibson042 If you don't mind, I'll take your suggestion and make it into a different PR that could supersede this one, since you've already done the hard part. |
ptomato
pushed a commit
to ptomato/test262
that referenced
this pull request
Apr 3, 2025
Taken from Richard's suggestion in tc39#4428 (review)
See #4447 |
ptomato
added a commit
to ptomato/test262
that referenced
this pull request
Apr 5, 2025
Taken from Richard's suggestion in tc39#4428 (review) Co-Authored-By: André Bargull <[email protected]> Co-Authored-By: Philip Chimento <[email protected]>
ptomato
added a commit
to ptomato/test262
that referenced
this pull request
Apr 7, 2025
Taken from Richard's suggestion in tc39#4428 (review) Co-Authored-By: André Bargull <[email protected]> Co-Authored-By: Philip Chimento <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Also see unicode-org/cldr#4375.