Socket
Socket
Sign inDemoInstall

ebx-timezone-mock

Package Overview
Dependencies
2
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ebx-timezone-mock

A JavaScript library which mocks the Date object and lets you specify a local date/time/timezone in order to enable consistent testing of date/time-related code independently of your local system time settings.


Version published
Weekly downloads
149
decreased by-56.3%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

1.1.4

Changes:

  • Compiled TimezoneMock.js - mental note, this stuff really needs automating...

Readme

Source

ebx-timezone-mock

A JavaScript library which mocks the Date object and lets you specify a local date/time/timezone in order to enable consistent testing of date/time-related code independently of your local system time settings.

It works by monkey patching the Date object and returning results which are adjusted to reflect the effects of both the specified current date/time/timezone (if any) and the current date/time/timezone. In particular, it avoids problems caused by certain JavaScript date/time methods e.g. getHours returning results in the user's local system time, so you can write date/time-related unit tests which will work whenever and wherever they are run, without changing timezones causing results to change.

Installation

NPM

$ npm install ebx-timezone-mock

Usage

Configuration

import TimezoneMock from 'TimezoneMock';

TimezoneMock.set('2018-04-25T12:34:56.000Z');

console.log(new Date()); // Wed Apr 25 2018 12:34:56 GMT+0000 (GMT Standard Time)

TimezoneMock.reset();

console.log(new Date()); // Current system date/time/timezone

Credits

The majority of the code for this project was taken from the timezone-mock project by Jimb Esser, with some additional code from the MockDate project by Bob Lauer. My contribution has been limited to gluing these two projects together, and introduction moment-timezone to solve the problem of working out the timezone offset for any given date, time and place.

Keywords

FAQs

Last updated on 15 May 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc