Parse an ISO 8601 duration to a TimeInterval
Install using Swift Package Manager:
dependencies: [
.package(url: "https://github.com/LinusU/ParseISODuration", from: "1.0.0"),
]
import ParseISODuration
try! TimeInterval(fromISODuration: "PT8S") // 8 * 1000
try! TimeInterval(fromISODuration: "PT10M") // 10 * 60 * 1000
try! TimeInterval(fromISODuration: "PT20H") // 20 * 60 * 60 * 1000
try! TimeInterval(fromISODuration: "PT6M4S") // 6 * 60 * 1000 + 4 * 1000
try! TimeInterval(fromISODuration: "P10Y10M10D") // Throws ParseISODurationError.ambiguousDuration
try! TimeInterval(fromISODuration: "Hello world") // Throws ParseISODurationError.invalidDuration
If years or months is specified and more than 0 the library will throw ParseISODurationError.ambiguousDuration
since its meaning can't be converted to milliseconds.
- Node.js version: LinusU/node-parse-iso-duration
MIT