Socket
Socket
Sign inDemoInstall

duration-parser

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    duration-parser

parse time durations written in plain english


Version published
Weekly downloads
210
decreased by-22.22%
Maintainers
1
Install size
32.8 kB
Created
Weekly downloads
 

Readme

Source

duration-parser

parse time durations written in plain english

Build Status Dependency Status devDependency Status

NPM

usage

It's a function that parses a duration string and returns the number of milliseconds that duration represents.

var parseDuration = require(`duration-parser`);      

parseDuration('1 second');  // 1000
parseDuration('2 seconds'); // 2000
parseDuration('3.4s');      // 3400

parseDuration('1 minute 9 seconds');     //  69000
parseDuration('1 minute - 10 seconds');  //  50000
parseDuration('-1 minute + 10 seconds'); // -50000
parseDuration('-1 minute   10 seconds'); // -70000

It understands the following time constructs and abbreviations.

  • milliseconds: milliseconds, millisecond, ms
  • seconds:seconds , second , secs , sec , s
  • minutes: minutes , minute , mins , min , m
  • hours: hours , hour , hrs , hr , h
  • days: days , day , d
  • weeks: weeks , week , wks , wk , w

+ / - and order of operations

+ and - operators perform addition and subtraction as expected. Concatenating time measurements together (with or without whitespace) will perform addition.

'1h3s' == '1h + 3s' == '1 hour 3 seconds'

Concatenation has higher precedence than the + or - operators, so:

'1 week - 2 days 6 hours' == '1 week - (2 days + 6 hours)'

(parenthesis are not currently supported)

releasing

  1. ensure your git working directory is clean (git status).
  2. ensure you are running npm 2.13 or later, or 3.1 or later (npm --version, npm i npm@latest).
  3. ensure you have cut-release installed (npm i -g cut-release).
  4. run cut-release.

FAQs

Last updated on 21 Jul 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc