npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

minitz

v4.0.6

Published

Minimal utility to convert between timezones in JavaScript/TypeScript. Deno/Node/Browser. ESM/CommonJS.

Downloads

110

Readme

minitz

Node.js CI Deno CI npm version NPM Downloads jsdelivr Codacy Badge MIT License

Minitz offers an efficient way to manage and manipulate time zone in native JavaScript Date objects. With a modern ES-module design and full typings, minitz is compatible with any environment that supports JavaScript or TypeScript. Highlights:

  • Convert dates between any timezone supported by the system.
  • Parses ISO8601 time strings.
  • MIT licensed, use the library any way you want. For real.
  • Minimal (less than 2 KB minified), no dependencies. Relies on JavaScript Intl and current best practices.
  • Works in Node.js >=14.0 (both require and import).
  • Works in Deno >=1.8.
  • Works in Bun >=0.2.2
  • Works in browsers as standalone, UMD or ES-module.
  • Includes TypeScript typings.

Try Minitz live on jsfiddle

Check out the full documentation at minitz.56k.guru

Usage

While converting a Date object to another timezone in JavaScript is achievable using the Intl feature of vanilla JS, things can get complicated when you want to convert date/time from another timezone or between different timezones. See the following examples:

Vanilla js for converting to a specific time zone:

// Get current time in Asia/Tokyo, using vanilla js
new Date().toLocaleString("sv-SE", { timeZone: "Asia/Tokyo" });
// -> 2022-09-15 17:23:45

Using minitz to convert from and across different time zones:

// Get local time from time in Asia/Tokyo, using minitz and vanilla js
const localTime = minitz(2022,9,15,23,0,0,"Asia/Tokyo")
console.log( localTime.toLocaleString("sv-SE") );
// -> 2022-09-15 16:00:00
// Get time in America/New_York from time in Asia/Tokyo, using minitz and vanilla js
// Also demonstrates that it's possible to use ISO8601 strings as input to minitz, 
// through `.fromTZISO`
const localTime = minitz.fromTZISO("2022-09-15 23:00:00","Asia/Tokyo");
console.log( localTime.toLocaleString("sv-SE", { timeZone: "America/New_York" }) );
// -> 2022-09-15 10:00:00

Installation

Details on installation for various platforms, including Node.js, Deno, Bun, and browsers, can be found in the full documentation. A few installation commands are:

Node.js: npm install minitz

Deno: import minitz from "https://deno.land/x/[email protected]/src/minitz.js";

Bun: bun add minitz

For CDN, refer to the documentation.

Contributing

Any contributions are welcome. See the Contribution guide to get started.

Donations

If you found this library helpful and wish to support its development, consider making a donation through Hexagon's GitHub Sponsors page. Your generosity ensures the library's continued development and maintenance.

License

MIT