Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@vvo/tzdb
Advanced tools
Simplified, grouped and always up to date list of time zones, with major cities
@vvo/tzdb is an npm package that provides a comprehensive database of time zones. It allows developers to easily access and manipulate time zone data, including retrieving time zone names, offsets, and other related information.
Get all time zones
This feature allows you to retrieve a list of all available time zones. The code sample demonstrates how to use the `getTimeZones` function to get an array of time zone objects.
const { getTimeZones } = require('@vvo/tzdb');
const timeZones = getTimeZones();
console.log(timeZones);
Get time zone by name
This feature allows you to retrieve detailed information about a specific time zone by its name. The code sample shows how to use the `getTimeZone` function to get details for the 'America/New_York' time zone.
const { getTimeZone } = require('@vvo/tzdb');
const timeZone = getTimeZone('America/New_York');
console.log(timeZone);
Get time zone offset
This feature allows you to get the offset of a specific time zone. The code sample demonstrates how to use the `getTimeZoneOffset` function to get the offset for the 'America/New_York' time zone.
const { getTimeZoneOffset } = require('@vvo/tzdb');
const offset = getTimeZoneOffset('America/New_York');
console.log(offset);
Moment-timezone is a popular package that extends the Moment.js library to handle time zones. It provides similar functionalities to @vvo/tzdb, such as retrieving time zone data and converting between time zones. However, it is built on top of Moment.js, which can be heavier and more complex compared to @vvo/tzdb.
Luxon is a modern JavaScript library for working with dates and times. It includes built-in support for time zones and offers a more modern API compared to Moment.js. Luxon provides similar functionalities to @vvo/tzdb but also includes additional features for date and time manipulation.
Date-fns-tz is an extension of the date-fns library that adds support for time zones. It provides functions to convert dates between time zones and to get time zone offsets. Date-fns-tz offers a lightweight and functional approach to handling time zones, similar to @vvo/tzdb.
This is a list and npm package of:
Pacific Time
instead of America/Los_Angeles
, along with major cities for each time zone.The data and npm packages are automatically updated whenever there are changes to https://www.geonames.org/ which is generated from IANA databases.
This is useful whenever you want to build a time zone select menu in your application.
This is most probably what you're looking for if you're trying to build a time zones selector in your application.
Example data:
[
// ...
{
name: "America/Anchorage",
alternativeName: "Alaska Time",
mainCities: ["Anchorage", "Juneau"],
formatted: "-09:00 Alaska Time - Anchorage, Juneau",
group: [
"America/Anchorage",
"America/Juneau",
"America/Metlakatla",
"America/Nome",
"America/Sitka",
"America/Yakutat",
],
},
{
name: "Pacific/Gambier",
alternativeName: "Gambier Time",
mainCities: ["Gambier"],
formatted: "-09:00 Gambier Time - Gambier",
group: ["Pacific/Gambier"],
},
{
name: "America/Los_Angeles",
alternativeName: "Pacific Time",
mainCities: ["Los Angeles", "San Diego"],
formatted: "-08:00 Pacific Time - Los Angeles, San Diego",
group: ["America/Los_Angeles"],
},
// ...
];
As you can see, we provide the time zone name and a pre-formatted version using more common offset names.
Notes:
formatTimeZone
to compute the same formatted structure, with the current date offset, at runtime instead of buildtimeThis is the raw list of all IANA time zones ranked by alphabetical order.
Example data:
[
// ...
"America/La_Paz",
"America/Lima",
"America/Los_Angeles",
"America/Lower_Princes",
"America/Maceio",
"America/Managua",
"America/Manaus",
"America/Marigot",
"America/Martinique",
// ...
];
Installation:
npm add @vvo/tzdb
Usage:
import { simplifiedTimeZones, timeZonesNames, formatTimeZone } from "@vvo/tzdb";
You can use this function when you want to get a formatted time zone but with the current date offset. This is useful if you always want to show the real, current time zone offset.
Example usage:
import { simplifiedTimeZones, formatTimeZone } from "@vvo/tzdb";
console.log(
formatTimeZone(simplifiedTimeZones[10], { useCurrentOffset: true }),
);
// output when in DST:
// -07:00 Pacific Time - Los Angeles, San Diego
This function uses luxon internally, so it would be better for your build size to also use luxon in your application whenever you need to manipulate dates.
PS: If you'd like to contribute to this library, we could make it so that formatTimeZone is not luxon dependant, for example taking the code here: https://github.com/mobz/get-timezone-offset. Open an issue!
You can store cities information on a search engine like Algolia. There's a yarn generate
command you can use if you clone this repository to create your own Algolia index. The expected environment variables are:
ALGOLIA_APPLICATION_ID=... ALGOLIA_ADMIN_API_KEY=... ALGOLIA_INDEX_NAME=... yarn build
Here's a demo of the index:
FAQs
Always up to date list of time zones, with grouping and major cities
The npm package @vvo/tzdb receives a total of 125,334 weekly downloads. As such, @vvo/tzdb popularity was classified as popular.
We found that @vvo/tzdb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.