Require correct hour-cycle setting instead of either h11 or h12 resp. h23 or h24

This commit is contained in:
André Bargull 2017-12-21 12:08:22 -08:00 committed by Rick Waldron
parent 72db5f1ec1
commit f65bd7af7a
1 changed files with 21 additions and 35 deletions

View File

@ -14,50 +14,36 @@ includes: [testIntl.js, propertyHelper.js]
/* Values passed via unicode extension key work */
/**
* Since at the moment of writing, CLDR does not provide data for any locale
* that would allow it to use both 0-based and 1-based hourCycles,
* we can only test if the result is within the pair of h11/h12 or h23/h24.
*/
const hcValuePairs = [
["h11", "h12"],
["h23", "h24"]
];
const hcValues = ['h11', 'h12', 'h23', 'h24'];
const hour12Values = ['h11', 'h12'];
const hour24Values = ['h23', 'h24'];
const dataPropertyDesc = { writable: true, enumerable: true, configurable: true };
for (const hcValuePair of hcValuePairs) {
for (const hcValue of hcValuePair) {
const resolvedOptions = new Intl.DateTimeFormat(`de-u-hc-${hcValue}`, {
hour: 'numeric'
}).resolvedOptions();
for (const hcValue of hcValues) {
const resolvedOptions = new Intl.DateTimeFormat(`de-u-hc-${hcValue}`, {
hour: 'numeric'
}).resolvedOptions();
assert(hcValuePair.includes(resolvedOptions.hourCycle));
assert.sameValue(resolvedOptions.hour12, hour12Values.includes(hcValue));
assert.sameValue(resolvedOptions.hourCycle, hcValue);
assert.sameValue(resolvedOptions.hour12, hour12Values.includes(hcValue));
verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc);
verifyProperty(resolvedOptions, 'hour12', dataPropertyDesc);
}
verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc);
verifyProperty(resolvedOptions, 'hour12', dataPropertyDesc);
}
/* Values passed via options work */
for (const hcValuePair of hcValuePairs) {
for (const hcValue of hcValuePair) {
const resolvedOptions = new Intl.DateTimeFormat(`en-US`, {
hour: 'numeric',
hourCycle: hcValue
}).resolvedOptions();
for (const hcValue of hcValues) {
const resolvedOptions = new Intl.DateTimeFormat(`en-US`, {
hour: 'numeric',
hourCycle: hcValue
}).resolvedOptions();
assert(hcValuePair.includes(resolvedOptions.hourCycle));
assert.sameValue(resolvedOptions.hour12, hour12Values.includes(hcValue));
assert.sameValue(resolvedOptions.hourCycle, hcValue);
assert.sameValue(resolvedOptions.hour12, hour12Values.includes(hcValue));
verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc);
verifyProperty(resolvedOptions, 'hour12', dataPropertyDesc);
}
verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc);
verifyProperty(resolvedOptions, 'hour12', dataPropertyDesc);
}
/* When both extension key and option is passed, option takes precedence */
@ -67,7 +53,7 @@ let resolvedOptions = new Intl.DateTimeFormat(`en-US-u-hc-h12`, {
hourCycle: 'h23'
}).resolvedOptions();
assert(['h23', 'h24'].includes(resolvedOptions.hourCycle));
assert.sameValue(resolvedOptions.hourCycle, 'h23');
assert.sameValue(resolvedOptions.hour12, false);
verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc);
@ -81,7 +67,7 @@ resolvedOptions = new Intl.DateTimeFormat(`fr`, {
hourCycle: 'h23'
}).resolvedOptions();
assert(['h11', 'h12'].includes(resolvedOptions.hourCycle));
assert(hour12Values.includes(resolvedOptions.hourCycle));
assert.sameValue(resolvedOptions.hour12, true);
verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc);
@ -94,7 +80,7 @@ resolvedOptions = new Intl.DateTimeFormat(`fr-u-hc-h24`, {
hour12: true,
}).resolvedOptions();
assert(['h11', 'h12'].includes(resolvedOptions.hourCycle));
assert(hour12Values.includes(resolvedOptions.hourCycle));
assert.sameValue(resolvedOptions.hour12, true);
verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc);