Skip to content

Commit c7a5857

Browse files
Lxxyxdanielleadams
authored andcommitted
test: set locale for datetime-change-notify test
The time zone output by toString() will change with user's language, use toLocaleString() to set the time zone. PR-URL: #38741 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 18f3ba3 commit c7a5857

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

test/parallel/test-datetime-change-notify.js

+24-11
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,27 @@ if (!isMainThread)
1111

1212
const assert = require('assert');
1313

14-
process.env.TZ = 'Etc/UTC';
15-
assert.match(new Date().toString(), /GMT\+0000/);
16-
17-
process.env.TZ = 'America/New_York';
18-
assert.match(new Date().toString(), /Eastern (Standard|Daylight) Time/);
19-
20-
process.env.TZ = 'America/Los_Angeles';
21-
assert.match(new Date().toString(), /Pacific (Standard|Daylight) Time/);
22-
23-
process.env.TZ = 'Europe/Dublin';
24-
assert.match(new Date().toString(), /Irish/);
14+
const cases = [
15+
{
16+
timeZone: 'Etc/UTC',
17+
expected: /Coordinated Universal Time/,
18+
},
19+
{
20+
timeZone: 'America/New_York',
21+
expected: /Eastern (Standard|Daylight) Time/,
22+
},
23+
{
24+
timeZone: 'America/Los_Angeles',
25+
expected: /Pacific (Standard|Daylight) Time/,
26+
},
27+
{
28+
timeZone: 'Europe/Dublin',
29+
expected: /Irish/,
30+
},
31+
];
32+
33+
for (const { timeZone, expected } of cases) {
34+
process.env.TZ = timeZone;
35+
const date = new Date().toLocaleString('en-US', { timeZoneName: 'long' });
36+
assert.match(date, expected);
37+
}

0 commit comments

Comments
 (0)