Skip to content

Commit

Permalink
test: set locale for datetime-change-notify test
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
  • Loading branch information
Lxxyx authored and danielleadams committed May 31, 2021
1 parent 18f3ba3 commit c7a5857
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions test/parallel/test-datetime-change-notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,27 @@ if (!isMainThread)

const assert = require('assert');

process.env.TZ = 'Etc/UTC';
assert.match(new Date().toString(), /GMT\+0000/);

process.env.TZ = 'America/New_York';
assert.match(new Date().toString(), /Eastern (Standard|Daylight) Time/);

process.env.TZ = 'America/Los_Angeles';
assert.match(new Date().toString(), /Pacific (Standard|Daylight) Time/);

process.env.TZ = 'Europe/Dublin';
assert.match(new Date().toString(), /Irish/);
const cases = [
{
timeZone: 'Etc/UTC',
expected: /Coordinated Universal Time/,
},
{
timeZone: 'America/New_York',
expected: /Eastern (Standard|Daylight) Time/,
},
{
timeZone: 'America/Los_Angeles',
expected: /Pacific (Standard|Daylight) Time/,
},
{
timeZone: 'Europe/Dublin',
expected: /Irish/,
},
];

for (const { timeZone, expected } of cases) {
process.env.TZ = timeZone;
const date = new Date().toLocaleString('en-US', { timeZoneName: 'long' });
assert.match(date, expected);
}

0 comments on commit c7a5857

Please sign in to comment.