Swiftpack.co - longinius/swift-duration as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by longinius.
longinius/swift-duration 1.0.0
An ISO 8601 Duration parser for Swift.
⭐️ 2
🕓 42 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/longinius/swift-duration.git", from: "1.0.0")

Swift ISO 8601 Duration

An ISO 8601 Duration parser for Swift. Inspired by the Luxon Duration object.

Features

  • Parses ISO 8601 formatted duration strings (e.g. "P1D" or "PT1H15M").
  • Supports Codable protocol.
  • Works with negative durations.
  • Create a DateComponents object from Duration.
  • Extensions for Calendar to use Duration like DateComponents.

Usage

Create a duration from an ISO 8601 string.

let duration = Duration(fromISO: "P2Y4M12DT5H34M48S")

// Duration contains the parsed values
duration.year // 2
duration.month // 4
duration.day // 12
duration.hour // 5
duration.minute // 34
duration.second // 48

Get a DateComponents object from duration.

let dateComponents = duration.dateComponents

Installation

The Swift Package Manager is a tool for managing the distribution of Swift Code. It's integrated into the swift compiler.

To use Duration in your project, simply add this Package as dependency:

dependencies: [
    .package(url: "https://github.com/longinius/swift-duration.git", .upToNextMajor(from: "1.0.0"))
]

GitHub

link
Stars: 2
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.0.0
43 weeks ago

Duration 1.0 is the first release. It adds the basic elements.

Features

  • Add Duration class and internal Parser for duration strings.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics