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

@snps/datetime

v0.0.2

Published

Zero-dependency date and time library with duration support

Readme

@snps/datetime

Zero-dependency date and time library with duration support.

Installation

pnpm install @snps/datetime

API

DateTime

The DateTime class provides an immutable way to work with dates and times.

Constructor

Creates a new DateTime instance. If no date is provided, it defaults to the current date and time.

import { DateTime } from '@snps/datetime';

const now = new DateTime();
const specificDate = new DateTime(new Date('2023-10-27T10:00:00.000Z'));

now()

Creates a new DateTime instance for the current date and time.

const now = DateTime.now();

fromTimestamp(ms: number)

Creates a new DateTime instance from a timestamp in milliseconds.

const dt = DateTime.fromTimestamp(1609459200000);

parse(dateString: string)

Creates a new DateTime instance from an ISO 8601 string.

const dt = DateTime.parse('2021-01-01T00:00:00.000Z');

fromDate(year: number, month: number, day: number = 1)

Creates a new DateTime instance from year, month, and day components.

const dt = DateTime.fromDate(2021, 1, 15);

format(formatString: string)

Formats the DateTime instance as a string.

const dt = DateTime.fromDate(2021, 3, 15);
dt.format('YYYY-MM-DD'); // '2021-03-15'

toISO()

Formats the DateTime instance as an ISO 8601 string.

const dt = DateTime.parse('2021-03-15T14:30:45.123Z');
dt.toISO(); // '2021-03-15T14:30:45.123Z'

relative(from?: DateTime)

Returns the relative time from the DateTime instance to the from date (or now).

const past = DateTime.fromTimestamp(Date.now() - 30000);
past.relative(); // '30 seconds ago'

add(duration: DateDuration)

Adds a duration to the DateTime instance.

const dt = DateTime.fromDate(2021, 1, 1);
const newDt = dt.add({ years: 1, months: 2, days: 3 });

subtract(duration: DateDuration)

Subtracts a duration from the DateTime instance.

const dt = DateTime.fromDate(2021, 5, 15);
const newDt = dt.subtract({ years: 1, months: 2, days: 3 });

startOfDay()

Returns a new DateTime instance set to the start of the day.

const dt = DateTime.parse('2021-01-15T14:30:45.123Z');
const start = dt.startOfDay();

endOfDay()

Returns a new DateTime instance set to the end of the day.

const dt = DateTime.parse('2021-01-15T14:30:45.123Z');
const end = dt.endOfDay();

isBefore(other: DateTime)

Checks if the DateTime instance is before another DateTime instance.

const dt1 = DateTime.fromDate(2021, 1, 1);
const dt2 = DateTime.fromDate(2021, 1, 2);
dt1.isBefore(dt2); // true

isAfter(other: DateTime)

Checks if the DateTime instance is after another DateTime instance.

const dt1 = DateTime.fromDate(2021, 1, 1);
const dt2 = DateTime.fromDate(2021, 1, 2);
dt2.isAfter(dt1); // true

isSame(other: DateTime)

Checks if the DateTime instance is the same as another DateTime instance.

const dt1 = DateTime.fromTimestamp(1609459200000);
const dt2 = DateTime.fromTimestamp(1609459200000);
dt1.isSame(dt2); // true

Getters

  • getYear(): number
  • getMonth(): number
  • getDay(): number
  • getHours(): number
  • getMinutes(): number
  • getSeconds(): number
  • valueOf(): number
  • toDate(): Date