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

@pj1401/date-utils

v1.2.2

Published

Date utilities

Readme

date-utils

This is a collection of utility methods for the Date object.

Install

Using npm:

npm i @pj1401/date-utils

Usage

Import:

import { DateUtil } from "@pj1401/date-utils";

const dateUtil = new DateUtil()

Methods:

countDays

countDays(date: Date): number

Returns the number of days until a date. If the date is in the past, the number of days passed is returned (negative).

const nextWeek = new Date()
nextWeek.setDate(nextWeek.getDate() + 7)

dateUtil.countDays(nextWeek) // returns 7

dateUtil.countDays(new Date('2025-09-30')) // returns a negative number

getWeekNumber

getWeekNumber(date: Date): number

Returns the number of the week that the date is in.

dateUtil.getWeekNumber(new Date('2025-09-17')) // returns 38

getOrdinalDate

getOrdinalDate(date: Date): number

Returns the number representing the day of the year.

dateUtil.getOrdinalDate(new Date('2025-09-30')) // returns 273

getDaysBetween

getDaysBetween(date1: Date, date2: Date): number

Returns the number of days between two dates.

dateUtil.getDaysBetween(new Date('2025-09-15'), new Date('2025-09-22')) // returns 7

getDatesBetween

getDatesBetween(startDate: Date, endDate: Date): Date[]

Get an array of dates between two dates, inclusive.

dateUtil.getDatesBetween(new Date('2025-10-25'), new Date('2025-11-02'))

getQuarter

getQuarter(date: Date): number

Returns the quarter of the year the date is in.

dateUtil.getQuarter(new Date('2025-10-01')) // returns 4

isBetween

isBetween(date: Date, startDate: Date, endDate: Date): boolean

Check if a date is in the interval [startDate, endDate].

dateUtil.isBetween(new Date('2025-09-30'), new Date('2025-09-29'), new Date('2025-10-01')) // true

startOfWeek

startOfWeek(date: Date): Date

Returns the start (Monday) of the week the date is in.

dateUtil.startOfWeek(new Date('2025-09-30')) // returns a Date object set to 2025-09-29

endOfWeek

endOfWeek(date: Date): Date

Returns the end (Sunday) of the week the date is in.

dateUtil.endOfWeek(new Date('2025-09-30')) // returns a Date object set to 2025-10-05

getDaysUntilWeekend

getDaysUntilWeekend(date: Date): number

Get the number of days until the weekend (Saturday). If the date argument is a Sunday, it counts the days until the next weekend. If no argument is passed the current date will be used.

dateUtil.getDaysUntilWeekend(new Date('2025-11-05')) // returns 3

countWorkingDays

countWorkingDays(startDate: Date, endDate: Date): number

Get the number of working days between two dates.

dateUtil.countWorkingDays(new Date('2025-10-20'), new Date('2025-11-01')) // returns 10

addDays

addDays(date: Date, numberOfDays: number): Date

Add days to the date. The returned date is a different instance from the date argument.

dateUtil.addDays(new Date('2025-01-30'), 5) // returns a Date object set to 2025-02-04

removeDays

removeDays(date: Date, numberOfDays: number): Date

Remove days from the date. The returned date is a different instance from the date argument.

dateUtil.addDays(new Date('2025-01-03'), 10) // returns a Date object set to 2024-12-24

Testing

See Testing instructions