ISO8601DurationFormatter

1.2.1

A formatter for converting ISO8601 durations to DateComponents.
kkla320/ISO8601DurationFormatter

What's New

2020-12-29T15:18:37Z

ISO8601DurationFormatter

A formatter for converting ISO 8601 durations to DateComponents.

Installation

Swift Package Manager

Add the following to your Package.swift file's dependencies:

.package(url: "https://github.com/kkla320/ISO8601DurationFormatter.git", from: "1.1.0")

And then import wherever needed

import ISO8601DurationFormatter

Example

Converting a string to DateComponents

let input = "PT40M"
let dateComponents = formatter.dateComponents(from: input)
if let dateComponents = dateComponents {
    print(dateComponents.minute) // 40
}

Converting DateComponents to string

let dateComponents = DateComponents(year: 6,
                                    month: 2,
                                    day: 2,
                                    hour: 4,
                                    minute: 44,
                                    second: 22,
                                    weekOfYear: 2)

let ISO8601DurationString = dateComponents.toISO8601Duration()
print(ISO8601DurationString) // P6Y2M2W2DT4H44M22S

Special thanks to Igor-Palaguta for implementing the most in his project YoutubeEngine.

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Nov 11 2021 04:18:55 GMT-0500 (GMT-05:00)