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

zoned-date-time

v1.1.0

Published

A tiny JavaScript Date with full IANA timezone support

Downloads

2,673

Readme

ZonedDateTime

A tiny (0.6KB) JavaScript Date with IANA timezone support.

Usage

npm install --save zoned-date-time iana-tz-data
import ZonedDateTime from "zoned-date-time";
import {zoneData} from "iana-tz-data";
let date = new Date("2017-03-15T12:00:00Z");

let losAngelesDate = new ZonedDateTime(date, zoneData.America.Los_Angeles);
// > 2017-03-15T05:00:00.000 PDT (daylight savings)

let newYorkDate = new ZonedDateTime(date, zoneData.America.New_York);
// > 2017-03-15T08:00:00.000 EDT (daylight savings)

let saoPauloDate = new ZonedDateTime(date, zoneData.America.Sao_Paulo);
// > 2017-03-15T09:00:00.000 -03

losAngelesDate.isDST(); // > true
saoPauloDate.isDST(); // > false

I18n disclaimer

Important note on i18n: If you need to display such information to your users/customers, use an i18n library. For example:

API

Constructor

new ZonedDateTime(date, timeZoneData)

Creates a new zonedDateTime instance given a date and timeZoneData.

date

A JavaScript date object, i.e., new Date().

timeZoneData

The zdumped IANA timezone data (found on the iana-tz-data package) for the desired timeZoneId.

Methods

.clone()

Returns a cloned zoned date time instance.

.getDate()

Returns the day of the month.

.getDay()

Returns the day of the week.

.getFullYear()

Returns the full year, e.g., 2017.

.getHours()

Returns the hours, ranges from 0 to 23.

.getMilliseconds()

Returns the milliseconds.

.getMinutes()

Returns the minutes, ranges from 0 to 59.

.getMonth()

Returns the month number, ranges from 0 to 11.

.getSeconds()

Returns the seconds, ranges from 0 to 59.

.getTime()

Returns the numeric value corresponding to the time for the specified date according to universal time, i.e., the epoch time.

.getTimezoneOffset()

Returns the time zone difference, in minutes, from its zone to UTC.

.isDST()

Returns a boolean indicating whether the datetime is in daylight savings mode.

.setDate(dayValue)

Sets the day of the object relative to the beginning of the currently set month according to this zone.

dayValue

An integer representing the day of the month.

.setFullYear(yearValue)

Sets the full year according to this zone.

yearValue

An integer specifying the numeric value of the year, for example, 1995.

.setHours(hoursValue)

Sets the hours according to this zone.

hoursValue

An integer between 0 and 23, representing the hour.

.setMilliseconds(millisecondsValue)

Sets the milliseconds according to this zone.

millisecondsValue

A number between 0 and 999, representing the milliseconds.

.setMinutes(minutesValue)

Sets the minutes according to this zone.

minutesValue

An integer between 0 and 59, representing the minutes.

.setMonth(monthValue)

Sets the month according to this zone.

monthValue

An integer between 0 and 11, representing the months January through December.

.setSeconds(secondsValue)

Sets the seconds according to this zone.

secondsValue

An integer between 0 and 59, representing the seconds.

.setTime(timeValue)

Sets the numeric value corresponding to the time for the specified date according to universal time, i.e., the epoch time.

timeValue

An integer representing the number of milliseconds since 1 January 1970, 00:00:00 UTC.

.toDate()

Returns the corresponding Date object, i.e., the equivalent date in the runtime time zone.

.toISOString()

Returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset, as denoted by the suffix "Z".

.toJSON()

Returns a string representation of the Date object.

.toUTCString()

Converts a date to a string, using the UTC time zone.

License

MIT © Rafael Xavier de Souza

MIT © Ramalingam Kandaswamy Manikandan