buildasaurs / XcodeServerSDK

Access Xcode Server API with native Swift objects.
MIT License
399 stars 30 forks source link

Date from array #78

Closed cojoj closed 9 years ago

cojoj commented 9 years ago

@czechboy0 I can't find this anywhere in code so I'll simply ask. In some responses we're getting date but in form of array of components. Didiyou write a method or extension for handling this? I only found dateForKey() and optionalDateForKey() but they work with Strings.

We need something to get this array by calling arrayForKey() and return NSDateComponents or date formatted String.

Got any hints how you want it to be implemented? Here are my ideas:

In any case we'll have to manually take fields fromArray and put them in NSDateComponents like:

let components = NSDateComponents()

components.year = array[0]
components.month = array[1]
components.day = array[2]
components.hour = array[3]
components.minute = array[4]
components.second = array[5]

Which kind of sucks... What's more, Array of components we get from XCS has 7 fields and I wonder what is the 7th one... It doesn't look like a timezone... Nanoseconds?

cojoj commented 9 years ago

The old one [XCS] returns Array of 6 Ints but the new one has 7...

cojoj commented 9 years ago

Confirmed 👌

7th field is a time is same as in String version, so it's SSSZZZZ.

In that case we can convert [Int] to String and pass it to the regular method from JSON.swift. That way we'll save some memory as calendar calculations are expensive.

czechboy0 commented 9 years ago

If that works (would probably warrant a test case for both Xcode 6 and 7) then :+1:

Good job reverse engineering it ;) That's how we do things here! On Thu, Jul 23, 2015 at 8:18 AM Mateusz Zając notifications@github.com wrote:

Confirmed 👌

7th field is a time is same as in String version, so it's SSSZZZZ.

In that case we can convert [Int] to String and pass it to the regular method from JSON.swift. That way we'll save some memory as calendar calculations are expensive.

— Reply to this email directly or view it on GitHub https://github.com/czechboy0/XcodeServerSDK/issues/78#issuecomment-124002978 .

czechboy0 commented 9 years ago

Fixed in https://github.com/buildasaurs/BuildaUtils/pull/1