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 🙏

© 2025 – Pkg Stats / Ryan Hefner

chronos-helper

v1.1.7

Published

A handy tool for date manipulation.

Readme

chronos-helper

A lightweight and easy-to-use NPM toolkit for date manipulation tasks. Perform operations like formatting dates, adding days, checking weekends, converting time zones, add business days, and much more.

Installation

Install the package via NPM:

npm install chronos-helper

Usage

const { 
    formatDate, 
    addDays, 
    isWeekend, 
    toReadableString, 
    convertTimeZone, 
    timeAgo, 
    timeUntil, 
    getRecurringDates, 
    isBusinessDay, 
    getNextBusinessDay, 
    calculateBusinessDays 
} = require('chronos-helper');

const date = new Date('2024-11-19');

// Format a date
console.log(formatDate(date, 'DD/MM/YYYY')); // "19/11/2024"

// Add days to a date
console.log(formatDate(addDays(date, 5), 'YYYY-MM-DD')); // "2024-11-24"

// Check if a date is a weekend
console.log(isWeekend(date)); // false

// Convert a date to a readable string
console.log(toReadableString(date)); // "19 November 2024"

// Convert time zones
const utcDate = new Date('2024-11-19T12:00:00Z');
console.log(convertTimeZone(utcDate, 'UTC', 'Europe/Brussels')); // Adjusted to Belgium time

// Check how long ago a date occurred
console.log(timeAgo(new Date('2024-11-15'))); // "4 days ago"

// Check how far a date is in the future
console.log(timeUntil(new Date('2024-11-25'))); // "6 days from now"

// Generate recurring dates
console.log(getRecurringDates(new Date('2024-11-01'), 'weekly', 3)); // Weekly dates for 3 occurrences

// Check if a date is a business day
console.log(isBusinessDay(date)); // true

// Get the next business day
console.log(getNextBusinessDay(new Date('2024-11-23'))); // "2024-11-25" (Monday)

// Calculate business days between two dates
console.log(calculateBusinessDays(new Date('2024-11-01'), new Date('2024-11-10'))); // 6 business days

Features

formatDate(date, format)

Formats a JavaScript Date object into a specified string format.

  • Parameters:
    • date: A JavaScript Date object.
    • format: The desired format string, e.g., 'YYYY-MM-DD' or 'DD/MM/YYYY'.
  • Returns: A formatted date string.

Example

formatDate(new Date('2024-11-19'), 'YYYY-MM-DD'); // "2024-11-19"
formatDate(new Date('2024-11-19'), 'DD/MM/YYYY'); // "19/11/2024"

addDays(date,days)

Adds a specified number of days to a JavaScript Date objet.

  • Parameters;
    • date: A JavaScript Date object
    • days: The number of days to add (can be negative to subtract days).
  • Returns: A new Date object with the updated date.

Example:

addDays(new Date('2024-11-19'), 5); // "2024-11-24"

isWeekend(date)

Checks if a given date falls on a weekend (Saturday or Sunday)

  • Parameters:
    • date: A JavaScript Date object.
  • Returns: true if the date is a weekend, otherwise false.

Example:

isWeekend(new Date('2024-11-23')); // true (Saturday)
isWeekend(new Date('2024-11-19')); // false (Tuesday)

toReadableString(date)

Converts a JavaScript Date object into a human-readable string.

  • Parameters:
    • date: A JavaScript Date object.
  • Returns: A string in the format "DD Month YYYY", e.g., "19 November 2024".

Example:

toReadableString(new Date('2024-11-19')); // "19 November 2024"

convertTimeZone(date, fromZone, toZone)

Converts a Date from one time zone to another.

  • Parameters:
    • date: A JavaScript Date object.
    • fromZone: The source time zone (e.g., 'UTC').
    • toZone: The target time zone (e.g., 'Europe/Brussels').
  • Returns: A new Date object in the target time zone.

Example:

convertTimeZone(new Date('2024-11-19T12:00:00Z'), 'UTC', 'Europe/Brussels');

timeAgo(date)

Calculates how long ago a given date occurred relative to now.

  • Parameters:
    • date: A JavaScript Date object.
  • Returns: A human-readable string like "2 days ago".

Example:

timeAgo(new Date('2024-11-15')); // "4 days ago"

timeAgo(date)

Calculates how far a date is in the future relative to now.

  • Parameters:
    • date: A JavaScript Date object.
  • Returns: A human-readable string like "3 days from now".

Example:

timeUntil(new Date('2024-11-25')); // "6 days from now"

getRecurringDates(startDate, frequency, occurrences)

Generates recurring dates based on a starting date and frequency.

  • Parameters:
    • startDate: A JavaScript Date object.
    • frequency: 'daily', 'weekly', 'monthly', or 'yearly'.
    • occurrences: The number of occurrences to generate.
  • Returns: An array of Date objects.

Example:

getRecurringDates(new Date('2024-11-01'), 'weekly', 3); // Recurring weekly dates

isBusinessDay(date)

Checks if a given date falls on a business day (Monday to Friday).

Example:

isBusinessDay(new Date('2024-11-19')); // true

getNextBusinessDay(date)

Finds the next business day after a given date.

Example:

getNextBusinessDay(new Date('2024-11-23')); // Monday, 2024-11-25

calculateBusinessDays(startDate, endDate)

Calculates the number of business days between two dates.

Example:

calculateBusinessDays(new Date('2024-11-01'), new Date('2024-11-10')); // 6

Testing

This package uses Jest for unit tests. Run the tests using:

npm test

License

This project is licensed under the MIT License