diff options
author | ZiJian Liu <Lxxyxzj@gmail.com> | 2021-05-20 08:22:38 +0300 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2021-05-31 22:34:52 +0300 |
commit | c7a58578dc1fc3bb26e39026ac58a1072064a572 (patch) | |
tree | 2608bd1ad59a36f9deafa45d9659a4ed4ad167e6 /test | |
parent | 18f3ba3674aef389ee58b0f744aa12843168754a (diff) |
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: https://github.com/nodejs/node/pull/38741
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-datetime-change-notify.js | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/test/parallel/test-datetime-change-notify.js b/test/parallel/test-datetime-change-notify.js index 94f126179b7..9cd6d7abfd8 100644 --- a/test/parallel/test-datetime-change-notify.js +++ b/test/parallel/test-datetime-change-notify.js @@ -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); +} |