diff options
author | ZiJian Liu <Lxxyxzj@gmail.com> | 2021-05-20 13:22:38 +0800 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-05-24 07:36:11 -0700 |
commit | 80ed0a66b5ac5754168db2e9e6b8021d596a0679 (patch) | |
tree | 7858e60f6d7c2bfecaeb74f8ff9b8d1a495b1aeb /test/parallel/test-datetime-change-notify.js | |
parent | 28e1b2e2f1a6bedc835db244226659bfcaa0f068 (diff) | |
download | node-new-80ed0a66b5ac5754168db2e9e6b8021d596a0679.tar.gz |
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/parallel/test-datetime-change-notify.js')
-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 94f126179b..9cd6d7abfd 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); +} |