Latest 1.2
Homepage https://github.com/MaciejGad/Duration
License MIT
Platforms ios 10.0
Authors

Duration Build Status

ISO 8601 duration implementation for Swift using Codable.

This micro-framework should help with handling duration written using the ISO 8601 standard. It allows parsing a string like "P3Y6M4DT12H30M5S" to TimeInterval. More about ISO 8601 standard you can read in wiki https://en.wikipedia.org/wiki/ISO_8601#Durations

Usage

We will assume that you have a JSON like this:

{
  "duration": "P3Y6M4DT12H30M5S"
}

then you can create your own structure:

import ISO8601Duration

struct Box: Codable {
  let duration: Duration
}

add load data in a typical way:

let data =  Data(bytes: "{"duration":"P3Y6M4DT12H30M5S"}".utf8) //load you data
let decoder = JSONDecoder()
let box = try decoder.decode(Box.self, from: data)
print(box.duration.timeInterval) //110615405.0

Installation

Use the CocoaPods.

Add to your Podfile

pod 'ISO8601Duration'

and then call

pod install

and import

import ISO8601Duration

Latest podspec

{
    "name": "ISO8601Duration",
    "version": "1.2",
    "summary": "ISO 8601 duration implementation for Swift using Codable",
    "description": "This micro-framework should help with handling duration written using the ISO 8601 standard. It allows parsing a string like "P3Y6M4DT12H30M5S" to TimeInterval.",
    "homepage": "https://github.com/MaciejGad/Duration",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Maciej Gad": "https://github.com/MaciejGad"
    },
    "social_media_url": "https://twitter.com/maciej_gad",
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/MaciejGad/Duration.git",
        "tag": "v1.2"
    },
    "source_files": "Duration/*.swift",
    "swift_version": "4.2"
}

Pin It on Pinterest

Share This