11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciif (!common.isMainThread)
61cb0ef41Sopenharmony_ci  common.skip('process.env.TZ is not intercepted in Workers');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciif (common.isWindows)  // Using a different TZ format.
91cb0ef41Sopenharmony_ci  common.skip('todo: test on Windows');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst date = new Date('2018-04-14T12:34:56.789Z');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciprocess.env.TZ = 'Europe/Amsterdam';
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciif (date.toString().includes('(Europe)'))
161cb0ef41Sopenharmony_ci  common.skip('not using bundled ICU');  // Shared library or --with-intl=none.
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciif ('Sat Apr 14 2018 12:34:56 GMT+0000 (GMT)' === date.toString())
191cb0ef41Sopenharmony_ci  common.skip('missing tzdata');  // Alpine buildbots lack Europe/Amsterdam.
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciif (date.toString().includes('(Central European Time)') ||
221cb0ef41Sopenharmony_ci    date.toString().includes('(CET)')) {
231cb0ef41Sopenharmony_ci  // The AIX and SmartOS buildbots report 2018 CEST as CET
241cb0ef41Sopenharmony_ci  // because apparently for them that's still the deep future.
251cb0ef41Sopenharmony_ci  common.skip('tzdata too old');
261cb0ef41Sopenharmony_ci}
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci// Text representation of timezone depends on locale in environment
291cb0ef41Sopenharmony_ciassert.match(
301cb0ef41Sopenharmony_ci  date.toString(),
311cb0ef41Sopenharmony_ci  /^Sat Apr 14 2018 14:34:56 GMT\+0200 \(.+\)$/);
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ciprocess.env.TZ = 'Europe/London';
341cb0ef41Sopenharmony_ciassert.match(
351cb0ef41Sopenharmony_ci  date.toString(),
361cb0ef41Sopenharmony_ci  /^Sat Apr 14 2018 13:34:56 GMT\+0100 \(.+\)$/);
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciprocess.env.TZ = 'Etc/UTC';
391cb0ef41Sopenharmony_ciassert.match(
401cb0ef41Sopenharmony_ci  date.toString(),
411cb0ef41Sopenharmony_ci  /^Sat Apr 14 2018 12:34:56 GMT\+0000 \(.+\)$/);
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci// Just check that deleting the environment variable doesn't crash the process.
441cb0ef41Sopenharmony_ci// We can't really check the result of date.toString() because we don't know
451cb0ef41Sopenharmony_ci// the default time zone.
461cb0ef41Sopenharmony_cidelete process.env.TZ;
471cb0ef41Sopenharmony_cidate.toString();
48