简体   繁体   中英

Javascript Date gives wrong Timezone in Karma test

Somehow after a Docker image rebuild, I started having problems with javascript timezone problem. It used to work, but after a Docker image update, somehow the resulting Date object does not obey the TZ setting anymore. As the result, our timezone depending Date string formatting tests are failing.

# in the tests
console.log(new Date("2016-04-01T00:00:00.000000+00:00"));
// It is very strange it says (Asia) at the end.
// In fact, it will say whatever I put in TZ
Fri Apr 01 2016 00:00:00 GMT+0000 (Asia)

# in Chrome developer tool
console.log(new Date());
Fri Apr 01 2016 08:00:00 GMT+0800 (CST)

gulpfile.js

gulp.task('test', ['_set_tpe_timezone'], runKarmaWebpackTests);
gulp.task('_set_tpe_timezone', function() {
  gutil.log('Setting timezone TZ = Asia/Taipei');
  process.env.TZ = 'Asia/Taipei';
  return;
});

I am using the following setup to run javascript tests:

  • Gulp + Karma
  • inside a Docker container
  • In gulpfile, execute the following setting before each test process.env.TZ = 'Asia/Taipei';
  • using headless Chrome 59
  • cat /etc/timezone = Etc/UTC

Although the root cause is not yet discovered, a solution was found. Since this problem did not appear before, but only after a docker system prune -a , the base image was updated to the latest, which introduce this bug.

As a temporary solution, I have switch back to the old base image and it works like before without other modifications. I am going to also report this to the phusion team.

original Dockerfile

FROM phusion/baseimage
...

new Dockerfile

FROM phusion/baseimage:0.9.21
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM