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

@288-toolkit/dates

v4.0.8

Published

A collection of functions to manipulate dates.

Downloads

1,102

Readme

Dates

A collection of functions to manipulate dates.

parseLocalDates

Converts a date, in the yyyy-mm-dd format, into a Date object, in the user's timezone, at midnight.

today

Timezone aware day.

Returns a date representing the user's current day of month, in the source timezone at midnight. This is useful for filtering events by the user's current day of month, since events are mostly displayed in the event's timezone. Simply setting "now" hours to 0 could result the wrong date being shown to the user if the date of month is different in the user's timezone (it works "sometimes").

Let's illustrate the problem with an example:

  • The user is in Japan, which is 9 hours ahead of UTC.
  • The source date is in Toronto, which is 4 or 5 hours behind UTC, depending on the time of year.
  • Both dates are stored as UTC.
  • Source dates are shown to ALL users in the source timezone.
  • When it's June 2nd in Japan, it still can be June 1st in Toronto.
  • To get the data in the future for a user, we need to filter by the user's current "today", which is June 2nd, but filter according to the source timezone, at midnight.

Toronto (UTC-4) 19 - 20 - 21 - 22 - 23 - 00 - 01 - 02 - 03 - 04 - 05 - 06 - 07 - 08 - 09 - 10 - 11 - 12 - 13 - 14 -----June 1st -------- | -- June 2nd ------------------------------------------------------------ UTC 23 - 00 - 01 - 02 - 03 - 04 - 05 - 06 - 07 - 08 - 09 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 -- | ---------------------- June 2nd ------------------------------------------------------------ Japan (UTC+9) 08 - 09 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - 00 - 01 - 02 - 03 --------------------------- June 2nd --------------------------------------- | - June 3rd 2023 - ^^^ We are here, June 2nd, 8 o'clock in the morning in Japan.

If now is 2023-06-02T08:00:00.000+0900, now is also:

  • 2023-06-01T23:00:00.000+0000 in UTC
  • 2023-06-01T19:00:00.000-0400 in Toronto

Since it's June 2nd for the user, we need to filter for events that starts after 2023-06-02T00:00:00.000-0400 which is:

  • 2023-06-02T04:00:00.000+0000 in UTC
  • 2023-06-02T13:00:00.000+0900 in Japan

Same thing applies to Vancouver with events in Paris.

Paris (UTC+2) 01 - 02 - 03 - 04 - 05 - 06 - 07 - 08 - 09 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 ------------------------------------------ June 2nd -------------------------------------------- Vancouver (UTC-7) 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - 00 - 01 - 02 - 03 - 04 - 05 - 06 - 07 - 08 - 09 - 10 - 11 ----- June 1st ---------------------- | -- June 2nd --------------------------------------------- ^^^ We are here, June 1st, 4pm in the afternoon in Vancouver.

If now is 2023-06-01T16:00:00.000-0700, now is also:

  • 2023-06-01T23:00:00.000+0000 UTC
  • 2023-06-02T01:00:00.000+0200 in Paris

Since it's June 1st for the user, we need to filter for events that starts after 2023-06-01T00:00:00.000+0200

  • 2023-05-31T23:00:00.000+0000 in UTC
  • 2023-05-31T16:00:00.000-0700 in Vancouver

Essentially, it's ${USER_YEAR}-${USER_MONTH}-${USER_DAY}T${START_OF_DAY}:00:00-${EVENT_OFFSET}.

Use options.timeZone to specify the source (the events) timezone. It defaults to the TIMEZONE constant.

Use options.now to specify the user's current day of month.

Use options.hourOfStartOfDay to specify the hour of the start of day in the source timezone. This is useful for late night events that start at 1am, for example.

Pros

Deals with DST and other timezone changes.

Caveats

Does not work precisely for timezones that are offset by 30 minutes. Will ALWAYS use the user's timezone, regardless of its input.