Running Karma in specific TimeZone

Recently, I had to write some tests related to date and time. In order to tests corner cases, in particular when the UTC date was different from the local date, I had to find a way to set the timezone for my tests.

There are countless posts and articles out there that explain how you can set a specific time, but I couldn’t find much about how to actually set the timezone. Many articles references how you could use your browser’s profiles to set it up, etc. But all of it seemed too complicated for my taste.

In the end, I came across a gitlab-foss commit by Takuya Nogushi. Simply setting the process.env.TZ variable will do the trick.

module.exports = function (config) {
        // your karm configuration
    // Fix the timezone
    process.env.TZ = 'America/New_York';

I have not tested with other browsers, but this works with Chrome. The possible values for TZ are available on Wikipedia.


Popular posts from this blog

Calling HttpClient async functions from constructors in ASP.NET 4.5

T4 templates: the lazy programmer’s friend