A JavaScript library to mock the local timezone for testing purposes. Version 1.4.2 is current stable, with infrequent releases. It replaces the global Date constructor with a mocked version that behaves as if in a specified timezone, including DST transitions. Key differentiators: lightweight, no dependencies, supports multiple timezones (US/Pacific, US/Eastern, Brazil/East, UTC, Europe/London, Australia/Adelaide) and GMT offsets, and includes TypeScript types. Unlike full timezone libraries, it focuses solely on mocking for testing, not on timezone conversions or comprehensive data.
npm install timezone-mockNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates registering mock timezone, creating a Date, and unregistering. Also shows DST transition test.
Use afterEach or cleanup hooks to call unregister().
Ensure Node >= 8 for consistent behavior, or avoid date string parsing in tests.
Use US/Pacific or US/Eastern for DST testing.
Remember Etc/GMT+N = UTC-N, not UTC+N.
Call register() first, then access timezone_mock._Date.
Use import { register } from 'timezone-mock' OR import * as timezoneMock from 'timezone-mock' then timezoneMock.register.Use UTC dates (new Date('2021-01-01T00:00:00Z')) or ensure consistent timezone handling.No dependency data recorded yet.