Swift Package Index


A formatter for converting ISO8601 durations to DateComponents.


  • The latest stable release is v1.2.1. Released 27 days ago.
  • The last commit to develop was 27 days ago.

Swift Version Compatibility

  • v1.2.1 and develop
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • v1.2.1 and develop
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

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.2.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.