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

@art-suite/art-core-time

v0.1.5

Published

The Standard Library for JavaScript that aught to be.

Readme

@art-suite/art-core-time

A comprehensive JavaScript library for time and date manipulation, formatting, and calculations. Provides utilities for easy conversion between units, finding specific date boundaries, and generating human-readable time strings.

Features

  • Flexible date and time formatting (formatDate).
  • Easy conversion to milliseconds, seconds, and Date objects.
  • Functions to find the start of various time periods (hour, day, week, month, year), with locale support.
  • Human-readable duration and time delta strings (humanDurationString, humanTimeDeltaString, timeAgo).
  • A variety of "nice" date and time string formatters.
  • Utilities for calculating date age and accessing current time components.
  • TypeScript definitions for complete type safety.

Installation

npm install @art-suite/art-core-time

API Overview

Formatting

  • formatDate(date?: Date | number | string, formatString?: string): string: Formats a date according to a given format string.
  • humanDurationString(durationInSeconds: number, options?: object): string: Converts a duration in seconds to a human-readable string (e.g., "1 hour 30 minutes").
  • humanTimeDeltaString(fromTime: Date | number, toTime?: Date | number, options?: object): string: Returns a human-readable string representing the time difference between two dates.
  • niceFullDateString(date?: Date | number | string): string: Formats a date into a nice, full string (e.g., "January 1, 2023").
  • niceMonthYear(date?: Date | number | string): string: Formats a date into a "Month Year" string (e.g., "January 2023").
  • niceDateString(date?: Date | number | string): string: Formats a date into a nice, concise date string.
  • niceTimeDetailsString(date?: Date | number | string): string: Formats a date into a string with detailed time information.
  • timeAgo(date: Date | number | string, now?: Date | number): string: Returns a string representing how long ago a date was (e.g., "5 minutes ago").

Conversions

  • toMilliseconds(value: any, unit?: string): number: Converts a time value from various units (like seconds, minutes, custom strings) to milliseconds.
  • toSeconds(value: any, unit?: string): number: Converts a time value to seconds.
  • toDate(value?: Date | number | string): Date: Converts a value (timestamp, string) to a Date object.

Date Boundary Calculations (Default/UTC)

  • firstOfHour(date?: Date | number | string): Date: Returns a Date object set to the beginning of the hour for the given date.
  • firstOfDay(date?: Date | number | string): Date: Returns a Date object set to the beginning of the day (midnight).
  • firstOfWeek(date?: Date | number | string, firstDayOfWeek?: number): Date: Returns a Date object set to the beginning of the week.
  • firstOfMonth(date?: Date | number | string): Date: Returns a Date object set to the beginning of the month.
  • firstOfYear(date?: Date | number | string): Date: Returns a Date object set to the beginning of the year.

Date Boundary Calculations (Locale-Aware)

  • firstOfDayLocale(date?: Date | number | string): Date: Beginning of the day, respecting local timezone.
  • firstOfWeekLocale(date?: Date | number | string, firstDayOfWeek?: number): Date: Beginning of the week, respecting local conventions.
  • firstOfMonthLocale(date?: Date | number | string): Date: Beginning of the month, respecting local timezone.
  • firstOfYearLocale(date?: Date | number | string): Date: Beginning of the year, respecting local timezone.

Time Constants & Names

  • normalizedTimeNames: Record<string, string>: A map of common time unit names to a normalized form (e.g., { second: "s", minute: "m" }).
  • longTimeNames: Record<string, string>: A map of normalized time unit names to their long forms (e.g., { s: "second", m: "minute" }).
  • secondsPer: Record<string, number>: A map defining the number of seconds per time unit (e.g., { minute: 60, hour: 3600 }).

Other Time Utilities

  • dateAgeInSeconds(date: Date | number | string): number: Calculates the age of a date in seconds from now.
  • time(): number: Returns the current time (typically as a Unix timestamp in milliseconds or seconds - to be clarified by implementation).
  • currentSecond(): number: Returns the current second of the minute (0-59) or potentially seconds since epoch.

Examples

Formatting Dates

import {
  formatDate,
  niceFullDateString,
  timeAgo,
} from "@art-suite/art-core-time";

const now = new Date();
console.log(formatDate(now, "YYYY-MM-DD HH:mm:ss")); // e.g., "2023-10-27 14:30:00"
console.log(niceFullDateString(now)); // e.g., "October 27, 2023"

const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000);
console.log(timeAgo(fiveMinutesAgo)); // "5 minutes ago"

Time Conversions

import { toMilliseconds, toDate } from "@art-suite/art-core-time";

console.log(toMilliseconds("5m")); // 300000 (5 minutes in milliseconds)
console.log(toMilliseconds(1, "hour")); // 3600000

const timestamp = 1672531200000; // Jan 1, 2023 UTC
console.log(toDate(timestamp).toUTCString()); // "Sun, 01 Jan 2023 00:00:00 GMT"

Date Boundaries

import { firstOfDay, firstOfMonthLocale } from "@art-suite/art-core-time";

const date = new Date("2023-10-27T15:45:00Z");
console.log(firstOfDay(date).toISOString()); // "2023-10-27T00:00:00.000Z"
console.log(firstOfMonthLocale(date).toString()); // Shows beginning of Oct in local time

License

MIT