formatRange-timeZone-offset.js (2594B)
1 // |reftest| skip-if(!this.hasOwnProperty("Intl")) 2 3 const { 4 Hour, Minute, Literal, TimeZoneName, 5 } = DateTimeFormatParts; 6 7 function hours(v) { 8 return v * 60 * 60 * 1000; 9 } 10 11 function minutes(v) { 12 return v * 60 * 1000; 13 } 14 15 const tests = { 16 "en": [ 17 { 18 start: 0, 19 end: minutes(2), 20 timeZone: "+00", 21 options: {hour: "numeric", minute: "numeric", hour12: false}, 22 timeZoneNames: { 23 short: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("GMT")], 24 shortOffset: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("GMT+0")], 25 shortGeneric: "short", 26 long: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("Greenwich Mean Time")], 27 longOffset: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("GMT+00:00")], 28 longGeneric: "long", 29 }, 30 }, 31 { 32 start: 0, 33 end: minutes(2), 34 timeZone: "-20:01", 35 options: {hour: "numeric", minute: "numeric", hour12: false}, 36 timeZoneNames: { 37 short: [Hour("03"), Literal(":"), Minute("59"), Literal(" – "), Hour("04"), Literal(":"), Minute("01"), Literal(" "), TimeZoneName("GMT-20:01")], 38 shortOffset: "short", 39 shortGeneric: "short", 40 long: "short", 41 longOffset: "short", 42 longGeneric: "short", 43 }, 44 }, 45 ], 46 "fr": [ 47 { 48 start: 0, 49 end: hours(2), 50 timeZone: "+17", 51 options: {hour: "numeric", hour12: false}, 52 timeZoneNames: { 53 short: [Hour("17"), Literal(" – "), Hour("19"), Literal(" "), TimeZoneName("UTC+17")], 54 shortOffset: "short", 55 shortGeneric: "short", 56 long: [Hour("17"), Literal(" – "), Hour("19"), Literal(" "), TimeZoneName("UTC+17:00")], 57 longOffset: "long", 58 longGeneric: "long", 59 }, 60 }, 61 ], 62 }; 63 64 for (let [locale, formats] of Object.entries(tests)) { 65 for (let {start, end, timeZone, options, timeZoneNames} of formats) { 66 for (let [timeZoneName, format] of Object.entries(timeZoneNames)) { 67 let df = new Intl.DateTimeFormat(locale, {timeZone, timeZoneName, ...options}); 68 if (typeof format === "string") { 69 format = timeZoneNames[format]; 70 } 71 assertRangeParts(df, start, end, format); 72 } 73 } 74 } 75 76 if (typeof reportCompare === "function") 77 reportCompare(0, 0, "ok");