zone-x
TypeScript icon, indicating that this package has built-in type declarations

0.20.4 • Public • Published

A Lightweight TimeZone Utility

Zone-X Logo

Overview

This library provides a set of functions to work with timezones in a web application. It includes functions for retrieving the user's timezone and retrieving a custom Date object. Works nicely in tandem with vitest time utils ( see below )

Usage

Example:

usage with vitest

const time = getCustomDate({
  timeZone: 'America/New_York',
  time: 'midnight',
});
vi.useFakeTimers();
vi.setSystemTime(time);

const pacificTime = getCustomDate({
  timeZone: 'America/Los_Angeles',
  time: '9pm',
});

console.log('PACIFIC TIME: ', pacificTime.toDateString());
// ^ PACIFIC TIME:  Sat Mar 09 2024
console.log('EASTERN TIME: ', vi.getMockedSystemTime()?.toDateString());
// ^ EASTERN TIME:  Sun Mar 10 2024
expect(pacificTime.getDate()).not.toEqual(vi.getMockedSystemTime()?.getDate());

Contributing We welcome contributions! If you find any issues or have suggestions for improvement, please open an issue or create a pull request.

Author Joel Rubin

Readme

Keywords

Package Sidebar

Install

npm i zone-x

Weekly Downloads

3

Version

0.20.4

License

none

Unpacked Size

135 kB

Total Files

14

Last publish

Collaborators

  • joelsrubin