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