https://github.com/linusu/node-parse-iso-duration
Parse an ISO 8601 duration to milliseconds
https://github.com/linusu/node-parse-iso-duration
hacktoberfest iso8601 iso8601-duration parse
Last synced: 5 months ago
JSON representation
Parse an ISO 8601 duration to milliseconds
- Host: GitHub
- URL: https://github.com/linusu/node-parse-iso-duration
- Owner: LinusU
- Created: 2015-01-25T16:40:07.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-12-04T16:07:56.000Z (almost 5 years ago)
- Last Synced: 2025-05-07T17:13:59.846Z (5 months ago)
- Topics: hacktoberfest, iso8601, iso8601-duration, parse
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 9
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# node-parse-iso-duration
Parse an ISO 8601 duration to milliseconds
## Instalation
```sh
npm install --save parse-iso-duration
```## Usage
```javascript
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 * 1000parseIsoDuration('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.
## Related
- Swift version: [LinusU/ParseISODuration](https://github.com/LinusU/ParseISODuration)
## License
MIT