Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
timezone-utility
Advanced tools
A comprehensive TypeScript utility for managing time zones. This package provides functionalities to list time zones, retrieve labels and values, filter by region, and convert between UTC and various time zones.
Install the package using npm:
npm install timezone-utilities
import TimeZone from "timezone-utilities";
Retrieve a list of all available timezones with both label and value.
const allTimezones = TimeZone.list();
console.log(allTimezones);
Output Example:
[
{ "label": "Africa/Abidjan", "value": "Africa/Abidjan" },
{ "label": "America/New_York", "value": "America/New_York" },
...
]
Get a list of timezone values (useful for APIs or forms where only the value is needed).
const timezoneValues = TimeZone.listWithoutLabel();
console.log(timezoneValues);
Output Example:
[
"Africa/Abidjan",
"America/New_York",
...
]
Retrieve a list of timezone labels.
const timezoneLabels = TimeZone.listWithoutValue();
console.log(timezoneLabels);
Output Example:
[
"Africa/Abidjan",
"America/New_York",
...
]
Retrieve timezones for a specific region (e.g., America, Europe, Asia).
const americanTimezones = TimeZone.listByRegion("America");
console.log(americanTimezones);
Output Example:
[
{ "label": "America/New_York", "value": "America/New_York" },
{ "label": "America/Chicago", "value": "America/Chicago" },
...
]
Retrieve the label (human-readable name) for a given timezone value.
const labelFromValue = TimeZone.getLabelFromValue("America/New_York");
console.log(labelFromValue);
Output Example:
"Eastern Standard Time"
Retrieve the timezone value from a label.
const valueFromLabel = TimeZone.getValueFromLabel("Eastern Standard Time");
console.log(valueFromLabel);
Output Example:
"America/New_York"
Retrieve a list of all available regions.
const regions = TimeZone.getRegions();
console.log(regions);
Output Example:
[
"Africa",
"America",
"Asia",
"Atlantic",
"Australia",
"Europe",
"Indian",
"Pacific"
]
Convert a UTC/GMT time to a specific timezone and format it in 12-hour or 24-hour format.
const utcDate = "2024-10-15T14:00:00Z";
const convertedTime = TimeZone.convertUTCToTimeZone(utcDate, 'America/New_York', { hour12: false });
console.log(convertedTime);
Output Example:
"10/15/2024, 10:00:00"
Convert a UTC/GMT time to a specific timezone and format it in 24-hour format.
const originalDate = "2024-10-15T14:00:00Z";
const convertedTime = TimeZone.convertBetweenTimeZones(originalDate, 'America/New_York', 'Asia/Dhaka', { hour12: true });
console.log(convertedTime);
Output Example:
"10/15/2024, 12:00:00 AM"
For time conversion, you can pass an options object:
hour12
: boolean – Specify whether to return the time in 12-hour or 24-hour format. Default is 24-hour.TimeZone.convertUTCToTimeZone(utcDate, 'America/New_York', { hour12: true });
Method Name | Description |
---|---|
TimeZone.list() | Get a list of all timezones (label-value pairs). |
TimeZone.listWithoutLabel() | Get a list of all timezone values. |
TimeZone.listWithoutValue() | Get a list of all timezone labels. |
TimeZone.listByRegion(region) | Get timezones by a specific region (e.g., "America", "Europe"). |
TimeZone.getLabelFromValue(value) | Get the timezone label for a specific value. |
TimeZone.getValueFromLabel(label) | Get the timezone value for a specific label. |
TimeZone.getRegions() | Get a list of all regions. |
TimeZone.convertUTCToTimeZone() | Convert a UTC date/time string to a specific timezone, with support for 12-hour and 24-hour formats. |
TimeZone.convertBetweenTimeZones() | Convert a date from one timezone to another and return the result in the target timezone format. |
This project is licensed under the MIT License.
We welcome contributions to this package! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
README.md
provides clear instructions for installation, usage, and examples for each method.convertUTCToTimeZone
method now includes an option for the 12-hour/24-hour format, as requested.FAQs
A versatile timezone management package designed for CommonJS, ES Module (ESM), JavaScript, and TypeScript projects.
We found that timezone-utility demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.