/Swift-ISO8601-DurationParser

Swift ISO8601 Parser

Primary LanguageSwiftMIT LicenseMIT

Swift/ISO8601-Duration Parser

Swift 4 Extension which converts ISO 8601 duration strings into a ‘DateComponents‘ object

Examples

PT12H = 12 hours
P3D = 3 days
P3DT12H = 3 days, 12 hours
P3Y6M4DT12H30M5S = 3 years, 6 months, 4 days, 12 hours, 30 minutes and 5 seconds
P10W = 70 days
For more information look here: https://en.wikipedia.org/wiki/ISO_8601#Durations

Usage

var durationString = "P3Y6M4DT12H30M5S"
var components = DateComponents.durationFrom8601String(durationString)

Donation

If you like my open source libraries, you can sponsor it! ☺️

paypal

License

This file is licensed under the MIT License.

Acknowledgments

Objective-C version from @kevinrandrup