Skip to content

Constructors and objects behave exactly like built-in Date; TZ offset is configurable

License

Notifications You must be signed in to change notification settings

thorn0/timezoned-date

Folders and files

NameName
Last commit message
Last commit date

Latest commit

May 18, 2017
47938c5 · May 18, 2017

History

44 Commits
May 16, 2017
May 18, 2017
May 18, 2017
Sep 19, 2015
Apr 1, 2017
Sep 19, 2015
May 16, 2017
May 18, 2017
May 16, 2017
May 16, 2017
Apr 1, 2017
May 16, 2017
May 18, 2017
May 18, 2017

Repository files navigation

timezoned-date Build Status npm

Constructors and objects behave exactly like built-in Date; the TZ offset is configurable

Tested against Test262 for the compatibility with Date.

No support for daylight saving time. Fixed offsets only.

Install

$ npm install --save timezoned-date

Usage

const timezonedDate = require('timezoned-date');
console.log(new Date());
// Sat Sep 19 2017 02:39:56 GMT+0300 (Ixania Daylight Time)
const UtcDate = timezonedDate.makeConstructor(0);
console.log(new UtcDate());
// Fri Sep 18 2017 23:39:56 GMT+0000 (UTC)
global.Date = timezonedDate.makeConstructor(240); // minutes
console.log(new Date());
// Sat Sep 19 2017 03:39:56 GMT+0400

An example of using it with jsdom:

const dom = new JSDOM(`<p>Hello</p>`, {
  beforeParse(window) {
    window.Date = timezonedDate.makeConstructor(240);
  }
});

API

makeConstructor(offsetInMinutes)

Returns a constructor function compatible with Date bound to the specified offset.

License

Apache 2.0 © 2013-2017 James A. Rosen, Georgii Dolzhykov

About

Constructors and objects behave exactly like built-in Date; TZ offset is configurable

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published