diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/intl402/DateTimeFormat/prototype/formatToParts/main.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/intl402/DateTimeFormat/prototype/formatToParts/main.js')
-rw-r--r-- | js/src/tests/test262/intl402/DateTimeFormat/prototype/formatToParts/main.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/DateTimeFormat/prototype/formatToParts/main.js b/js/src/tests/test262/intl402/DateTimeFormat/prototype/formatToParts/main.js new file mode 100644 index 0000000000..b42b917232 --- /dev/null +++ b/js/src/tests/test262/intl402/DateTimeFormat/prototype/formatToParts/main.js @@ -0,0 +1,76 @@ +// Copyright 2016 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: Tests for existance and behavior of Intl.DateTimeFormat.prototype.formatToParts +features: [Array.prototype.includes] +---*/ + +function reduce(parts) { + return parts.map(part => part.value).join(''); +} + +function compareFTPtoFormat(locales, options, value) { + const dtf = new Intl.DateTimeFormat(locales, options); + assert.sameValue( + dtf.format(value), + reduce(dtf.formatToParts(value)), + `Expected the same value for value ${value}, + locales: ${locales} and options: ${options}` + ); +} + +compareFTPtoFormat(); +compareFTPtoFormat('pl'); +compareFTPtoFormat(['pl']); +compareFTPtoFormat([]); +compareFTPtoFormat(['de'], undefined, 0); +compareFTPtoFormat(['de'], undefined, -10); +compareFTPtoFormat(['de'], undefined, 25324234235); +compareFTPtoFormat(['de'], { + day: '2-digit' +}, Date.now()); +compareFTPtoFormat(['de'], { + day: 'numeric', + year: '2-digit' +}, Date.now()); +compareFTPtoFormat(['ar'], { + month: 'numeric', + day: 'numeric', + year: '2-digit' +}, Date.now()); + +const actualPartTypes = new Intl.DateTimeFormat('en-us', { + weekday: 'long', + era: 'long', + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + hour12: true, + timeZone: 'UTC', + timeZoneName: 'long' +}).formatToParts(Date.UTC(2012, 11, 17, 3, 0, 42)) + .map(part => part.type); + +const legalPartTypes = [ + 'weekday', + 'era', + 'year', + 'month', + 'day', + 'hour', + 'minute', + 'second', + 'literal', + 'dayPeriod', + 'timeZoneName', +]; + +actualPartTypes.forEach(function(type) { + assert(legalPartTypes.includes(type), `${type} is not a legal type`); +}); + +reportCompare(0, 0); |