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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@papack/time

v1.0.1

Published

timestamp calculation and formatting utilities

Readme

@papack/time

Utility module for working with timestamps (milliseconds), durations, and formatting.

  • All values are milliseconds (Date.now() compatible)
  • Locale must always be passed explicitly

Import

import {
  // formatting
  formatRelative,
  formatDuration,
  formatDate,

  // time utils
  now,
  since,
  until,
  add,
  sub,

  // duration builders
  seconds,
  minutes,
  hours,
  days,

  // async
  sleep,

  // constants
  SECOND,
  MINUTE,
  HOUR,
  DAY,
  MONTH,
  YEAR,
} from "@papack/time";

Relative time

Formats a timestamp relative to now.

const ts = now() - 5 * MINUTE;

formatRelative(ts, "en");
// "5 minutes ago"

formatRelative(now() + 2 * HOUR, "en");
// "in 2 hours"

Behavior:

  • direction is automatic (past/future)
  • small deltas (<1s) are treated as “now” to avoid flicker
  • units: seconds -> years (month/year are approximations)

Duration

Formats a duration (not a timestamp).

formatDuration(2 * HOUR + 30 * MINUTE, "en");
// "2 hours, 30 minutes" (if Intl.DurationFormat is available)
// or "2h 30m" (fallback)

formatDuration(1 * DAY + 2 * HOUR, "en");
// "1 day, 2 hours"

formatDuration(0, "en");
// "0 minutes" or "0m"

Notes:

  • input is treated as absolute (Math.abs)
  • prefers Intl.DurationFormat
  • falls back to compact format if not available

Date formatting

Wrapper around Intl.DateTimeFormat.

formatDate(now(), "en", {
  dateStyle: "medium",
  timeStyle: "short",
});
// "May 4, 2026, 14:30"

Time helpers

Current time

now(); // number (ms)

Differences

const start = now() - 5 * MINUTE;

since(start); // elapsed ms
until(now() + 10 * MINUTE); // remaining ms

Arithmetic

const start = now();

add(start, 5 * MINUTE); // timestamp + duration
sub(start, 2 * HOUR); // timestamp - duration

Duration builders

seconds(5); // 5000
minutes(2); // 120000
hours(1); // 3600000
days(3); // 259200000

Used for readability:

add(now(), minutes(5));
await sleep(seconds(2));

Sleep

await sleep(1000);
await sleep(seconds(1));

Constants

All values are milliseconds.

5 * MINUTE;
2 * HOUR + 30 * MINUTE;

Available:

  • SECOND
  • MINUTE
  • HOUR
  • DAY
  • MONTH (~30 days, approximation)
  • YEAR (~365 days, approximation)

Typical usage

const expiresAt = add(now(), minutes(5));

formatRelative(expiresAt, locale);
// "in 5 minutes"

const elapsed = since(start);
// number (ms)

await sleep(seconds(1));

Notes

  • no timezone handling beyond Intl
  • month/year are approximations
  • output depends on runtime Intl support
  • all functions are pure (except sleep)