duration-to-seconds
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

duration-to-seconds

Converts an ISO 8601 duration to seconds

Installing

npm install duration-to-seconds

API

durationToSeconds(duration)

Converts the given ISO 8601 duration to seconds. A year ("Y") is regarded as 365 days. A month ("M") is regarded as 30 days. The behaviour is undefined when not given an ISO 8601 compliant string.

import durationToSeconds from "duration-to-seconds";

durationToSeconds("PT0.001S"); // => 0.001
durationToSeconds("PT0.000001S"); // => 0.000001
durationToSeconds("PT1S"); // => 1
durationToSeconds("PT1M"); // => 60
durationToSeconds("PT1H"); // => 3600
durationToSeconds("P1D"); // => 86400
durationToSeconds("P1W"); // => 604800
durationToSeconds("P1M"); // => 2592000
durationToSeconds("P1Y"); // => 31536000
durationToSeconds("P1Y1M1DT1H1M1S"); // => 34218061

Package Sidebar

Install

npm i duration-to-seconds

Weekly Downloads

55

Version

2.0.0

License

MIT

Unpacked Size

4.07 kB

Total Files

5

Last publish

Collaborators

  • rtomrud