@@ -15,7 +15,7 @@ public class IntegrationCommits: XcodeServerEntity {
15
15
public let botTinyID : String
16
16
public let botID : String
17
17
public let commits : [ String : [ Commit ] ]
18
- public let endedTimeDate : NSDate
18
+ public let endedTimeDate : NSDate ?
19
19
20
20
public required init ( json: NSDictionary ) {
21
21
self . integration = json. stringForKey ( " integration " )
@@ -27,6 +27,13 @@ public class IntegrationCommits: XcodeServerEntity {
27
27
super. init ( json: json)
28
28
}
29
29
30
+ /**
31
+ Method for populating commits property with data from JSON dictionary.
32
+
33
+ - parameter json: JSON dictionary with blueprints and commits for each one.
34
+
35
+ - returns: Dictionary of parsed Commit objects.
36
+ */
30
37
class func populateCommits( json: NSDictionary ) -> [ String : [ Commit ] ] {
31
38
var resultsDictionary : [ String : [ Commit ] ] = Dictionary ( )
32
39
@@ -42,17 +49,25 @@ public class IntegrationCommits: XcodeServerEntity {
42
49
return resultsDictionary
43
50
}
44
51
45
- class func parseDate( array: NSArray ) -> NSDate {
46
- let dateArray = array as! [ Int ]
52
+ /**
53
+ Parser for data objects which comes in form of array.
54
+
55
+ - parameter array: Array with date components.
56
+
57
+ - returns: Optional parsed date to the format used by Xcode Server.
58
+ */
59
+ class func parseDate( array: NSArray ) -> NSDate ? {
60
+ guard let dateArray = array as? [ Int ] else {
61
+ Log . error ( " Couldn't parse XCS date array " )
62
+ return nil
63
+ }
47
64
48
65
do {
49
66
let stringDate = try dateArray. dateString ( )
50
- let formatter = NSDateFormatter ( )
51
- formatter. dateFormat = " yyyy-MM-dd'T'HH:mm:ss.SSSZZZZ "
52
67
53
- guard let date = formatter . dateFromString ( stringDate) else {
68
+ guard let date = NSDate . dateFromXCSString ( stringDate) else {
54
69
Log . error ( " Formatter couldn't parse date " )
55
- return NSDate ( )
70
+ return nil
56
71
}
57
72
58
73
return date
@@ -62,7 +77,7 @@ public class IntegrationCommits: XcodeServerEntity {
62
77
Log . error ( " Something went wrong while parsing date " )
63
78
}
64
79
65
- return NSDate ( )
80
+ return nil
66
81
}
67
82
68
83
}
0 commit comments