ISO8601PeriodDuration
Parse ISO 8601 period-duration strings into DateComponents
Install / Use
/learn @treatwell/ISO8601PeriodDurationREADME
ISO8601PeriodDuration
Usage
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.
Example
Consider the following struct:
struct Appointment: Decodable {
@ISO8601PeriodDuration var duration: DateComponents
}
Decoded with the following JSON:
{
"duration": "PT2H30M"
}
It'll yield:
DateComponents
.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
License
The contents of this repository are licensed under the Apache License, version 2.0.
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
