Intl.DateTimeFormat: formatToParts nitpicking

This commit is contained in:
Rick Waldron 2018-08-10 15:35:04 -04:00
parent c0e494eb6a
commit b893503aa8

View File

@ -40,37 +40,34 @@ compareFTPtoFormat(['ar'], {
}, Date.now()); }, Date.now());
const actualPartTypes = new Intl.DateTimeFormat('en-us', { const actualPartTypes = new Intl.DateTimeFormat('en-us', {
weekday: 'long', weekday: 'long',
era: 'long', era: 'long',
year: 'numeric', year: 'numeric',
month: 'numeric', month: 'numeric',
day: 'numeric', day: 'numeric',
hour: 'numeric', hour: 'numeric',
minute: 'numeric', minute: 'numeric',
second: 'numeric', second: 'numeric',
hour12: true, hour12: true,
timeZone: 'UTC', timeZone: 'UTC',
timeZoneName: 'long' timeZoneName: 'long'
}).formatToParts(Date.UTC(2012, 11, 17, 3, 0, 42)) }).formatToParts(Date.UTC(2012, 11, 17, 3, 0, 42))
.map(function (part) { return part.type; }); .map(part => part.type);
const legalPartTypes = [ const legalPartTypes = [
"weekday", 'weekday',
"era", 'era',
"year", 'year',
"month", 'month',
"day", 'day',
"hour", 'hour',
"minute", 'minute',
"second", 'second',
"literal", 'literal',
"dayPeriod", 'dayPeriod',
"timeZoneName" 'timeZoneName',
]; ];
actualPartTypes.forEach( actualPartTypes.forEach(function(type) {
function (type) { assert(legalPartTypes.includes(type), `${type} is not a legal type`);
assert( });
legalPartTypes.indexOf(type) !== -1,
type + " is not a legal type");
});