From c7a58578dc1fc3bb26e39026ac58a1072064a572 Mon Sep 17 00:00:00 2001 From: ZiJian Liu Date: Thu, 20 May 2021 13:22:38 +0800 Subject: [PATCH] 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 Reviewed-By: Richard Lau --- test/parallel/test-datetime-change-notify.js | 35 ++++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/test/parallel/test-datetime-change-notify.js b/test/parallel/test-datetime-change-notify.js index 94f126179b79de..9cd6d7abfd898a 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); +}