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

@checkdigit/time

v4.0.0

Published

Standard time handling

Downloads

1,508

Readme

Check Digit Time Library

Copyright (c) 2022-2024 Check Digit, LLC

The Check Digit time library is the officially sanctioned method for Check Digit services to deal with time. It is a partial implementation of the new TC39 Temporal proposal and date manipulation functions provided by date-fns. Features:

  • Nanosecond precision date times, simulated with Node's built-in high-resolution timer
  • Tests that verify compliance with latest TC39 polyfill
  • Designed to be removed once Temporal is included, by default, within V8.
  • Implements most of Temporal.Instant, except timezone/calendar functionality
  • Implements Temporal.Now.instant()
  • Stripped down date-fns functions
  • date-fns-tz for timezone support
  • formatUtc for formatting UTC dates

Temporal (vs the millisecond precision of standard Date built-in) is useful for webservices recording the time of events, where concurrent activity may occur and millisecond precision does not provide adequate uniqueness and ordering.

The date-fns library is included. The only locale currently supported is en-US, but otherwise contains all available functionality as of v3.6.0.

Additionally, the date-fns-tz library is included. Contains all available functionality as of v1.3.7 except that the code in fp folder is excluded, which contains functional programming related stuff that is not used at the moment.

formatUtc

The formatUtc function is a wrapper around date-fns-tz's format function, but with the following differences:

  • There is no options argument, timeZone is always UTC.

Generally speaking, formatUtc should be used in place of format or tzFormat, unless non-UTC time zones are required.

Important note about Instant.toString()

Unlike built-in Date.toISOString(), Instant.toString() will not add fractional second digits if those values are zero.

E.g.

new Date(0).toISOString() -> 1970-01-01T00:00:00.100Z

vs

Temporal.Instant(0n).toString() -> 1970-01-01T00:00:00.1Z

Why not just use the polyfill?

The polyfill is not production ready. The implementation is designed to be used in the browser so cannot make use of Node's high-resolution timer to more accurately simulate nanosecond precision time. Crucially, the polyfill does not guarantee always increasing nanosecond precision times on subsequent calls, which makes it a non-starter for recording the time of events in production webservices.

Installing and usage

npm install @checkdigit/time then:

import { Temporal } from '@checkdigit/time'; // delete this once Temporal becomes a built-in

// print out nanosecond-precision ISO8601 datetime
console.log('Current time', Temporal.Now.instant().toString());

For date-fns functionality:

import { formatUtc } from '@checkdigit/time';

console.log(formatUtc(new Date(), 'yyyy-MM-dd'));

Documentation

The stage 3 proposal can be found here: https://github.com/tc39/proposal-temporal

The reference documentation is here: https://tc39.es/proposal-temporal/docs/

The documentation for date-fns is here: https://date-fns.org/

The documentation for date-fns-tz is here: https://github.com/marnusw/date-fns-tz

Maintenance notes:

When updating the latest code from the original repositories, except making all the necessary changes to make them fully typescript compatible, please remember to carry over the patches to overcome the following issues:

  • spring-forward support
  • nanosecond support

Please search for [PATCH:] in the existing codebase.