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

chronobox

v1.6.0

Published

A TypeScript date manipulation library

Readme

ChronoBox

ChronoBox is a lightweight, versatile, and easy-to-use TypeScript library for handling date manipulation and formatting. It provides a powerful API for adding, subtracting, comparing, and formatting dates.

🚀 Features

  • Add and subtract time units (e.g., days, weeks, months, years) with ease
  • Calculate differences between dates in various time units
  • Retrieve individual components of a date
  • Format dates using custom formats
  • Built-in validation for date inputs
  • Fully written in TypeScript with strong type safety

📦 Installation

npm install chronobox

📖 API Reference

ChronoBox

The ChronoBox class provides a convenient and powerful API for date manipulation, formatting, and validation.

Constructor

new ChronoBox<TFormat extends DateFormat | CustomFormat = DateFormat>(date?: DateInput, format?: TFormat)
  • date (optional): The date to initialize the ChronoBox instance. If not provided, the current date and time will be used.
  • format (optional): The format for the date output. Defaults to DateFormat.ISO.

Methods

add<T extends TimeUnit>(amount: number, unit: T): ChronoBox<TFormat>

Adds a specified amount of time to the current date.

  • amount: The amount of time to add.
  • unit: The unit of time to add (e.g., TimeUnit.DAYS, TimeUnit.MONTHS, etc.).
  • returns: A new ChronoBox instance with the updated date.

subtract<T extends TimeUnit>(amount: number, unit: T): ChronoBox<TFormat>

Subtracts a specified amount of time from the current date.

  • amount: The amount of time to subtract.
  • unit: The unit of time to subtract.
  • returns: A new ChronoBox instance with the updated date.

diff(other: DateInput, unit: TimeUnit = TimeUnit.DAYS): number

Calculates the difference between the current date and another date in the specified time unit.

  • other: The other date to compare with.
  • unit: The unit of time for the difference (e.g., TimeUnit.DAYS, TimeUnit.MONTHS, etc.).
  • returns: The difference in the specified time unit.

getComponents(): DateComponents

Returns the individual components (year, month, day, hours, minutes, seconds, milliseconds) of the date.

  • returns: An object with the above structure.

formatDate(): string

Formats the current date according to the specified format.

  • returns: A string representation of the date based on the format.

isValid(): boolean

Checks whether the current date is valid.

  • returns: true if the date is valid, otherwise false.

toDate(): Date

Returns the underlying Date object from the ChronoBox instance.

  • returns: A Date object representing the current date.

withFormat<NewFormat extends DateFormat | CustomFormat>(newFormat: NewFormat): ChronoBox<NewFormat>

Creates a new ChronoBox instance with a different format.

  • newFormat: The new format for the date.
  • returns: A new ChronoBox instance with the updated format.

isAfter(other: DateInput, granularity: TimeUnit = TimeUnit.MILLISECONDS): boolean

Checks if this date is after the specified date.

  • other: The date to compare against.
  • granularity: The time unit granularity for comparison (defaults to milliseconds for exact comparison).
  • returns: true if this date is after the specified date.

isBefore(other: DateInput, granularity: TimeUnit = TimeUnit.MILLISECONDS): boolean

Checks if this date is before the specified date.

  • other: The date to compare against.
  • granularity: The time unit granularity for comparison (defaults to milliseconds for exact comparison).
  • returns: true if this date is before the specified date.

convertTimezone(date: Date | ChronoBox, fromTimezone: string, toTimezone: string): Date

Converts a date from one timezone to another

  • date: The date to convert.
  • fromTimezone: The source timezone (e.g., 'America/New_York').
  • toTimezone: The target timezone (e.g., 'Europe/London').
  • returns: A new Date object representing the same moment in the target timezone.

getTimezoneOffsetMinutes(date: Date | ChronoBox, timezone: string): number

Gets the timezone offset in minutes for a date in a specific timezone.

  • date: The date to get the offset for.
  • timezone: The timezone to get the offset for (e.g., 'America/New_York').
  • returns: The timezone offset in minutes (positive for timezones behind UTC, negative for timezones ahead of UTC).

isInDST(date: Date | ChronoBox, timezone: string): boolean

Checks if a date is in Daylight Saving Time (DST) for a specific timezone.

  • date: The date to check.
  • timezone: The timezone to check for DST (e.g., 'America/New_York').
  • returns: true if the date is in DST for the specified timezone, false otherwise.

findDSTTransitions(year: number, timezone: string): { start: Date | null; end: Date | null }

Finds the exact DST transition times for a given year in a specific timezone.

  • year: The year to find DST transitions for.
  • timezone: The timezone to check (e.g., 'America/New_York').
  • returns: An object with start and end properties containing the DST transition dates, or null if no DST.

startOf<T extends TimeUnit>(unit: T): ChronoBox<TFormat>

Gets the start of a specified time unit for the current date.

  • unit: The time unit to get the start of (e.g., day, hour, minute).
  • Returns: A new ChronoBox instance set to the start of the specified unit.

endOf<T extends TimeUnit>(unit: T): ChronoBox<TFormat>

Gets the end of a specified time unit for the current date.

  • unit: The time unit to get the end of (e.g., day, hour, minute).
  • Returns: A new ChronoBox instance set to the end of the specified unit.

fromNow(referenceDate?: DateInput): string

Gets a human-readable string representing the time difference between the current date and now.

  • referenceDate?: An optional date to compare against. Defaults to the current time.
  • Returns: A string representing the relative time difference, e.g., "5 minutes ago", "in 2 days".

📄 License

ChronoBox is open-source software, licensed under the MIT License.

❤️ Support

If you find ChronoBox helpful, please give it a ⭐️ on GitHub and share it with your fellow developers!