format-timeZone-offset.js (3372B)
1 // |reftest| skip-if(!this.hasOwnProperty("Intl")) 2 3 const { 4 Hour, Minute, Literal, TimeZoneName, 5 } = DateTimeFormatParts; 6 7 const tests = { 8 "en": [ 9 { 10 date: 0, 11 timeZone: "-23", 12 options: {hour: "numeric", minute: "numeric", hour12: false}, 13 timeZoneNames: { 14 short: [Hour("01"), Literal(":"), Minute("00"), Literal(" "), TimeZoneName("GMT-23")], 15 shortOffset: "short", 16 shortGeneric: "short", 17 long: [Hour("01"), Literal(":"), Minute("00"), Literal(" "), TimeZoneName("GMT-23:00")], 18 longOffset: "long", 19 longGeneric: "long", 20 }, 21 }, 22 { 23 date: 0, 24 timeZone: "+23:59", 25 options: {hour: "numeric", minute: "numeric", hour12: false}, 26 timeZoneNames: { 27 short: [Hour("23"), Literal(":"), Minute("59"), Literal(" "), TimeZoneName("GMT+23:59")], 28 shortOffset: "short", 29 shortGeneric: "short", 30 long: [Hour("23"), Literal(":"), Minute("59"), Literal(" "), TimeZoneName("GMT+23:59")], 31 longOffset: "long", 32 longGeneric: "long", 33 }, 34 }, 35 ], 36 "fr": [ 37 { 38 date: 0, 39 timeZone: "-23", 40 options: {hour: "numeric", minute: "numeric", hour12: false}, 41 timeZoneNames: { 42 short: [Hour("01"), Literal(":"), Minute("00"), Literal(" "), TimeZoneName("UTC\u{2212}23")], 43 shortOffset: "short", 44 shortGeneric: "short", 45 long: [Hour("01"), Literal(":"), Minute("00"), Literal(" "), TimeZoneName("UTC\u{2212}23:00")], 46 longOffset: "long", 47 longGeneric: "long", 48 }, 49 }, 50 { 51 date: 0, 52 timeZone: "+23:59", 53 options: {hour: "numeric", minute: "numeric", hour12: false}, 54 timeZoneNames: { 55 short: [Hour("23"), Literal(":"), Minute("59"), Literal(" "), TimeZoneName("UTC+23:59")], 56 shortOffset: "short", 57 shortGeneric: "short", 58 long: [Hour("23"), Literal(":"), Minute("59"), Literal(" "), TimeZoneName("UTC+23:59")], 59 longOffset: "long", 60 longGeneric: "long", 61 }, 62 }, 63 ], 64 "ar-EG": [ 65 { 66 date: 0, 67 timeZone: "+13:37", 68 options: {hour: "numeric", minute: "numeric", hour12: false}, 69 timeZoneNames: { 70 short: [Hour("١٣"), Literal(":"), Minute("٣٧"), Literal(" "), TimeZoneName("غرينتش+١٣:٣٧")], 71 shortOffset: "short", 72 shortGeneric: "short", 73 long: "short", 74 longOffset: "short", 75 longGeneric: "short", 76 }, 77 }, 78 ], 79 "zh": [ 80 { 81 date: 0, 82 timeZone: "+23:59", 83 options: {hour: "numeric", minute: "numeric", hour12: false}, 84 timeZoneNames: { 85 short: [TimeZoneName("GMT+23:59"), Literal(" "), Hour("23"), Literal(":"), Minute("59")], 86 shortOffset: "short", 87 shortGeneric: "short", 88 long: "short", 89 longOffset: "short", 90 longGeneric: "short", 91 }, 92 }, 93 ], 94 }; 95 96 for (let [locale, formats] of Object.entries(tests)) { 97 for (let {date, timeZone, options, timeZoneNames} of formats) { 98 for (let [timeZoneName, format] of Object.entries(timeZoneNames)) { 99 let df = new Intl.DateTimeFormat(locale, {timeZone, timeZoneName, ...options}); 100 if (typeof format === "string") { 101 format = timeZoneNames[format]; 102 } 103 assertParts(df, date, format); 104 } 105 } 106 } 107 108 if (typeof reportCompare === "function") 109 reportCompare(0, 0, "ok");