|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | + |
| 6 | +if (!common.isMainThread) |
| 7 | + common.skip('process.env.TZ is not intercepted in Workers'); |
| 8 | + |
| 9 | +if (common.isWindows) // Using a different TZ format. |
| 10 | + common.skip('todo: test on Windows'); |
| 11 | + |
| 12 | +const date = new Date('2018-04-14T12:34:56.789Z'); |
| 13 | + |
| 14 | +process.env.TZ = 'Europe/Amsterdam'; |
| 15 | + |
| 16 | +if (date.toString().includes('(Europe)')) |
| 17 | + common.skip('not using bundled ICU'); // Shared library or --with-intl=none. |
| 18 | + |
| 19 | +if ('Sat Apr 14 2018 12:34:56 GMT+0000 (GMT)' === date.toString()) |
| 20 | + common.skip('missing tzdata'); // Alpine buildbots lack Europe/Amsterdam. |
| 21 | + |
| 22 | +if (date.toString().includes('(Central European Time)') || |
| 23 | + date.toString().includes('(CET)')) { |
| 24 | + // The AIX and SmartOS buildbots report 2018 CEST as CET |
| 25 | + // because apparently for them that's still the deep future. |
| 26 | + common.skip('tzdata too old'); |
| 27 | +} |
| 28 | + |
| 29 | +assert.strictEqual( |
| 30 | + date.toString().replace('Central European Summer Time', 'CEST'), |
| 31 | + 'Sat Apr 14 2018 14:34:56 GMT+0200 (CEST)'); |
| 32 | + |
| 33 | +process.env.TZ = 'Europe/London'; |
| 34 | +assert.strictEqual( |
| 35 | + date.toString().replace('British Summer Time', 'BST'), |
| 36 | + 'Sat Apr 14 2018 13:34:56 GMT+0100 (BST)'); |
| 37 | + |
| 38 | +process.env.TZ = 'Etc/UTC'; |
| 39 | +assert.strictEqual( |
| 40 | + date.toString().replace('Coordinated Universal Time', 'UTC'), |
| 41 | + 'Sat Apr 14 2018 12:34:56 GMT+0000 (UTC)'); |
| 42 | + |
| 43 | +// Just check that deleting the environment variable doesn't crash the process. |
| 44 | +// We can't really check the result of date.toString() because we don't know |
| 45 | +// the default time zone. |
| 46 | +delete process.env.TZ; |
| 47 | +date.toString(); |
0 commit comments