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

@davidwells/parse-time

v1.0.0

Published

Parse messy time strings into JavaScript Date objects

Downloads

6

Readme

@davidwells/parse-time

Parse messy time strings into JavaScript Date objects.

Installation

npm install @davidwells/parse-time

Usage

const { parseTime } = require('@davidwells/parse-time');

// Parse specific dates and times
const date1 = parseTime('January 15th 2024 at 3:30pm');
console.log(date1.toISOString()); // 2024-01-15T15:30:00.000Z

// Parse relative times
const now = new Date('2023-01-01T12:00:00Z');
const date2 = parseTime('in 2 hours', { now });
console.log(date2.toISOString()); // 2023-01-01T14:00:00.000Z

// Parse special keywords
const date3 = parseTime('today at 5pm', { now });
console.log(date3.toISOString()); // 2023-01-01T17:00:00.000Z

// Parse "never" (returns far future date)
const never = parseTime('never');
console.log(never.toISOString()); // 9999-12-31T00:00:00.000Z

// Parse "now" (returns current time)
const currentTime = parseTime('now');
console.log(currentTime.toISOString()); // Current time in ISO format

// Parse unix timestamp
const timestamp = 1672574400; // 2023-01-01T12:00:00Z
const date4 = parseTime(timestamp);
console.log(date4.toISOString()); // 2023-01-01T12:00:00.000Z

// Parse Date object
const dateObj = new Date('2023-05-15T10:30:00Z');
const date5 = parseTime(dateObj);
console.log(date5.toISOString()); // 2023-05-15T10:30:00.000Z

Supported Formats

The library supports a wide variety of time formats:

  • Specific dates and times: January 15th 2024 at 3:30pm, Dec 25 2023 midnight, July 4 2023 noon
  • Relative times: in 2 hours, 3 days ago, next week, next month
  • Special keywords: today at 5pm, yesterday noon, tomorrow at midnight
  • Time of day: 11am, 11pm, 12:30am, 12:30pm
  • Days of the week: this friday, next monday, last tuesday
  • Specific dates: oct 22nd 1987, 3pm oct 22nd 1987, the 22nd of october, 1987 at 7pm
  • Holidays: 4th of july, 9pm on the 4th of july
  • Relative periods: in 12 minutes, in 2 hours, in 31 hours, in 20 hours 40 minutes
  • Decimal periods: in 20.2h, in 1.5 weeks
  • Longer periods: in 5 weeks, in 2 years, in 2 years and 5 weeks
  • Past periods: 2 days ago, 2 days and 6 hours ago, 1 month ago, 14 days ago
  • ISO format: 2015-10-31, 2015-10-31 20:30, 2015-10-31 8:30pm

Options

The parseTime function accepts an options object as its second parameter:

const options = {
  now: new Date() // Reference date for relative time calculations
}

const date = parseTime('tomorrow at noon', options)

About

Fork of https://github.com/substack/parse-messy-time/blob/master/index.js

License

MIT