1 // first things first, set the timezone; see tzset(3)
2 process.env.TZ = 'Europe/Amsterdam';
4 var common = require('../common');
5 var assert = require('assert');
6 var spawn = require('child_process').spawn;
8 /* For the moment we are not going to support setting the timezone via the
9 * environment variables. The problem is that various V8 platform backends
10 * deal with timezone in different ways. The windows platform backend caches
11 * the timezone value while the Linux one hits libc for every query.
13 https://github.com/joyent/node/blob/08782931205bc4f6d28102ebc29fd806e8ccdf1f/deps/v8/src/platform-linux.cc#L339-345
14 https://github.com/joyent/node/blob/08782931205bc4f6d28102ebc29fd806e8ccdf1f/deps/v8/src/platform-win32.cc#L590-596
17 // time difference between Greenwich and Amsterdam is +2 hours in the summer
18 date = new Date('Fri, 10 Sep 1982 03:15:00 GMT');
19 assert.equal(3, date.getUTCHours());
20 assert.equal(5, date.getHours());
24 // changes in environment should be visible to child processes
25 if (process.argv[2] == 'you-are-the-child') {
26 // failed assertion results in process exiting with status code 1
27 assert.equal(false, 'NODE_PROCESS_ENV_DELETED' in process.env);
28 assert.equal(42, process.env.NODE_PROCESS_ENV);
29 assert.equal('asdf', process.env.hasOwnProperty);
30 var hasOwnProperty = Object.prototype.hasOwnProperty;
31 var has = hasOwnProperty.call(process.env, 'hasOwnProperty');
32 assert.equal(true, has);
35 assert.equal(Object.prototype.hasOwnProperty, process.env.hasOwnProperty);
36 var has = process.env.hasOwnProperty('hasOwnProperty');
37 assert.equal(false, has);
39 process.env.hasOwnProperty = 'asdf';
41 process.env.NODE_PROCESS_ENV = 42;
42 assert.equal(42, process.env.NODE_PROCESS_ENV);
44 process.env.NODE_PROCESS_ENV_DELETED = 42;
45 assert.equal(true, 'NODE_PROCESS_ENV_DELETED' in process.env);
47 delete process.env.NODE_PROCESS_ENV_DELETED;
48 assert.equal(false, 'NODE_PROCESS_ENV_DELETED' in process.env);
50 var child = spawn(process.argv[0], [process.argv[1], 'you-are-the-child']);
51 child.stdout.on('data', function(data) { console.log(data.toString()); });
52 child.stderr.on('data', function(data) { console.log(data.toString()); });
53 child.on('exit', function(statusCode) {
54 if (statusCode != 0) {
55 process.exit(statusCode); // failed assertion in child process