How to parse an ISO-8601 duration in Objective C?

Swift3,4,5 implementation:
https://github.com/Igor-Palaguta/YoutubeEngine/blob/master/Source/YoutubeEngine/Parser/NSDateComponents%2BISO8601.swift

Example:
let components = try DateComponents(ISO8601String: "P1Y2M3DT4H5M6S")

Tests:
https://github.com/Igor-Palaguta/YoutubeEngine/blob/master/Tests/YoutubeEngineTests/ISO8601DurationTests.swift

Update: fixed for DougSwith case "P3W3DT20H31M21"

Leave a Comment