Swiftpack.co -  treatwell/ISO8601PeriodDuration as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Parse ISO 8601 period-duration strings into DateComponents
.package(url: "https://github.com/treatwell/ISO8601PeriodDuration.git", from: "3.1.0")



Lightweight library to parse ISO 8601 period-duration strings into DateComponents, motivated by the lack of support for this standard in Foundation.

It's a rough equivalent of Java's PeriodDuration, except it only provides the parsing side of its functionality, leaving representation to the built-in DateComponents.

It leverages Swift 5.1's property wrappers in order to make parsing functionality as unintrusive as possible, optimistic for a seamless drop-in replacement when/if Apple ever introduces a similar solution into Foundation.


Consider the following struct:

struct Appointment: Decodable {
    @ISO8601PeriodDuration var duration: DateComponents

Decoded with the following JSON:

    "duration": "PT2H30M"

It'll yield:

    .year -> nil
    .month -> nil
    .day -> nil
    .hour -> 2
    .minute -> 30
    .second -> nil

Note: weeks (P3W) are supported, though they end up translated to days.

Author Information

David Roman - d@vidroman.dev


The contents of this repository are licensed under the Apache License, version 2.0.


Stars: 9
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

8 weeks ago
  • Added Hashable support for wrappers (#3).

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