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

@wazio/date-time

v0.1.1

Published

JavaScript/TypeScript DateTime library

Readme

Build Status Coverage Status styled with prettier

DateTime

A small JavaScript library written in TypeScript with some useful methods that I've always missed in JavaScript's Date object. Written without Regex. Based on C# DateTime class.

Installation

npm install @wazio/date-time

Test

npm test

Usage

import { DateTime, TimeSpan } from '@wazio/date-time';

// format
DateTime.format(new Date(2017, 5, 12, 16, 30), 'yyyy-MM-dd hh:mm tt'); // will output '2017-06-12 04:30 PM'

// parseExact
DateTime.parseExact('2017-06-12 04:30 PM', 'yyyy-MM-dd hh:mm tt'); // will be equal to new Date(2017, 5, 12, 16, 30)

// subtract
let timeSpan: TimeSpan = DateTime.subtract(new Date(2017, 5, 12, 16, 30), new Date(2017, 5, 11, 13, 30));
timeSpan.days; // will output 1
timeSpan.hours; // will output 3
timeSpan.totalDays; // will output 1.125
timeSpan.totalHours; // will output 27

// subtractDate
let timeSpan: TimeSpan = DateTime.subtractDate(new Date(2017, 5, 12, 16, 30), new Date(2017, 5, 11, 13, 30));
timeSpan.days; // will output 1
timeSpan.hours; // will output 0
timeSpan.totalDays; // will output 1
timeSpan.totalHours; // will output 24

// day checking with subtractDate
let timeSpan: TimeSpan = DateTime.subtractDate(new Date(2017, 5, 12, 16, 30), new Date(2017, 5, 13, 13, 30)); // second parameter is current date by default
let isYesterday: boolean = timeSpan.days === -1; // will output true
let isToday: boolean = timeSpan.days === 0; // will output false
let isTomorrow: boolean = timeSpan.days === 1; // will output false

Classes

DateTime

Methods

| Name | Description | | --- | ---| | static format(date: Date, format: string): string | Converts the value of the given Date object to its equivalent string representation using the specified format. | | static parseExact(datetime: string, format: string): Date | Converts the specified string representation of a date and time to its Date equivalent using the specified format. | | static subtract(date1: Date, date2: Date = new Date()): TimeSpan | Returns a new TimeSpan object based on date and time subtraction between given Date objects. | | static subtractDate(date1: Date, date2: Date = new Date()): TimeSpan | Returns a new TimeSpan object based on date subtraction between given Date objects. |

TimeSpan

Constructor
constructor(milliseconds: number);
constructor(hours: number, minutes: number, seconds: number);
constructor(days: number, hours: number, minutes: number, seconds: number, milliseconds?: number);
Methods

| Name | Description | | --- | ---| | get days(): number | Returns the days component of the time interval represented by the current TimeSpan structure. | | get hours(): number | Returns the hours component of the time interval represented by the current TimeSpan structure. | | get minutes(): number | Returns the minutes component of the time interval represented by the current TimeSpan structure. | | get seconds(): number | Returns the seconds component of the time interval represented by the current TimeSpan structure. | | get milliseconds(): number | Returns the milliseconds component of the time interval represented by the current TimeSpan structure. | | | | | get totalDays(): number | Returns the milliseconds value of the current TimeSpan structure expressed in whole and fractional days. | | get totalHours(): number | Returns the milliseconds value of the current TimeSpan structure expressed in whole and fractional hours. | | get totalMinutes(): number | Returns the milliseconds value of the current TimeSpan structure expressed in whole and fractional minutes. | | get totalSeconds(): number | Returns the milliseconds value of the current TimeSpan structure expressed in whole and fractional seconds. | | get totalMilliseconds(): number | Returns the milliseconds value of the current TimeSpan structure expressed in whole and fractional milliseconds. |

Format Specifiers

| Format specifier | Description | Example | Compatible with parseExact | | --- | --- | --- | --- | | Year | y | The year, from 0 to 99. | 7 | yes | | yy | The year, from 00 to 99. | 17 | yes | | yyy | The year, with a minimum of three digits. | 017 | yes | | yyyy | The year as a four-digit number. | 2017 | yes | | yyyyy | The year as a five-digit number. | 02017 | yes | || | Month | M | The month, from 1 through 12. | 6 | - | | MM | The month, from 01 through 12. | 06 | yes | || | Day | d | The day of the month, from 1 through 31. | 8 | - | | dd | The day of the month, from 01 through 31. | 08 | yes | || | Hour | h | The hour, using a 12-hour clock from 1 to 12. | 6 | - | | hh | The hour, using a 12-hour clock from 01 to 12. | 06 | yes | | H | The hour, using a 24-hour clock from 0 to 23. | 6 | - | | HH | The hour, using a 24-hour clock from 00 to 23. | 06 | yes | | t | The first character of the AM/PM designator. | P | yes | | tt | The AM/PM designator. | PM | yes | || | Minute | m | The minute, from 0 through 59. | 4 | - | | mm | The minute, from 00 through 59. | 04 | yes | || | Second | s | The second, from 0 through 59. | 9 | - | | ss | The second, from 00 through 59. | 09 | yes | || | Millisecond | f | The tenths of a second in a date and time value. | 8 | yes | | ff | The hundredths of a second in a date and time value. | 81 | yes | | fff | The milliseconds in a date and time value. | 813 | yes |