parse-iso-duration
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

node-parse-iso-duration

Parse an ISO 8601 duration to milliseconds

Instalation

npm install --save parse-iso-duration

Usage

var parseIsoDuration = require('parse-iso-duration');
 
parseIsoDuration('PT8S');   // 8 * 1000
parseIsoDuration('PT10M');  // 10 * 60 * 1000
parseIsoDuration('PT20H');  // 20 * 60 * 60 * 1000
parseIsoDuration('PT6M4S'); // 6 * 60 * 1000 + 4 * 1000
 
parseIsoDuration('Hello world'); // Throws "Invalid duration"
parseIsoDuration('P10Y10M10D');  // Throws "Ambiguous duration"

Year and month

If years or months is specified and more than 0 the library will throw "Ambiguous duration" since it's meaning can't be converted to milliseconds.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i parse-iso-duration

Weekly Downloads

16,449

Version

1.1.0

License

MIT

Unpacked Size

2.26 kB

Total Files

4

Last publish

Collaborators

  • linusu