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

chronoparse

v1.0.0

Published

Simple timespan string parser

Downloads

5

Readme

chronoparse

chronoparse is a simple nodejs module designed for parsing user-input timespan strings.
Currently it supports the format:

<quantity> <timespan>

Where <quantity> is a non-negative integer, and <timespan> is one of the following:

second, seconds, s
minute, minutes, m
hour, hours, h
day, days, d
week, weeks, w
month, months
year, years, y
decade, decades

chronoparse parses the given string, and returns an object using the following schema:

{
    totalSeconds, // an integer representing the total length of the timespan in seconds
    startDate, // the current datetime as of parsing completion
    endDate, // a datetime totalSeconds from startDate
    timezone, // the current local timezone, specified as "UTC+/-X" where X is the offset in hours
    parts // an array of each timespan string parsed
}

Usage

chronoparse exports a single function, called parse. This function takes a string to be parsed, and an optional options object.

const chronoparse = require("chronoparse");

let result1 = chronoparse("13 days");

console.log(result1.totalSeconds);
// expected output: 1123200

let result2 = chronoparse("2 minutes 3 seconds");

console.log(result2.totalSeconds);
// expected output: 123

The options object may contain any or all of the following options:

{
    delimiter, // a string to use to separate multiple timespans, defaults to whitespace
    max // a non-negative integer specifying the maximum number of timespans to parse in the string, defaults to no limit
}

Delimiters

chronoparse can handle compound timespans, such as 2 hours 20 minutes 14 seconds however, by default, it expects multiple timespans to be separated by only whitespace. If you wish to use other delimiters, such as commas, you should use the delimiter option:

let result = chronoparse("2 minutes, 3 seconds", {delimiter: ","});

console.log(result.totalSeconds);
// expected output: 123

Note that the trailing space after the delimiter does not need to be specified in the options object, as chronoparse will automatically trim whitespace from the start of the string before attempting to parse the next timespan.

Max timespans

In some situations, you may wish to only parse a certain number of timespans from the string. In such situations, you should use the max option:

let result = chronoparse("1 hour, 2 minutes, 3 seconds", { delimiter: ",", max: 2 });

console.log(result.totalSeconds);
// expected output: 3720

chronoparse will parse only the first max timespans in a string, and will stop parsing after it has parsed max timespans. This means that your string may contain anything, including invalid timespans, after max valid timespans, however this is not recommended.

let result = chronoparse("1 hour, 2 minutes, 3 is the coolest number", { delimiter: ",", max: 2 });

console.log(result.totalSeconds);
// expected output: 3720

NOTE: The default value of max is -1. This is interpreted as "no limit".

License and Usage

chronoparse is licensed under the MIT License, meaning it is provided as-is, and can be used freely for any purposes, commercial or otherwise. See LICENSE for the full license.