I am trying to convert the eBay timeLeft to a TimeInterval. The timeLeft value is returned from eBay as. Apparently the value is ISO 8601 (see link and question below). I believe the timeLeft is an interval relative to when I made the API call.
http://developer.ebay.com/Devzone/finding/CallRef/findItemsByKeywords.html
From eBay reference:
searchResult.item.sellingStatus.timeLeft
Time left before the listing ends. The duration is represented in the ISO 8601 duration format (PnYnMnDTnHnMnS). For listings that have ended, the time left is PT0S (zero seconds). See the "duration" type for information about this time format.
P10DT4H38M16S
Such that eBay Time Left Format:
P = Pending (INDICATOR OF ISO8601 DURATION)
1Y = 1 Year
2M = 2 Months
2D = Two Days
T = Time Separator (M is ambiguous)
16H = Sixteen hours
2M = Two minutes
40S = Forty seconds
I can format the string as follows, but this solution doesn't give me the ability process based on the attributes of the time left. For example. If the days are 0, I dont want to show "0 days". Ebay API ISO 8601 Date to timestamp
My specific question, is there a way to get this timeLeft into a swift 3.0 DateInterval so that I can use the functions native to the variable type?