var workingDaysInString String get var result String var leftBound wor

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var workingDaysInString: [String] {
get {
var result: [String] = []
var leftBound = workTimes[0]
var inArr = 1;
for i in 1..<workTimes.count {
if workTimes[i].start == leftBound.start &&
workTimes[i].end == leftBound.end {
inArr += 1
} else {
let startTimeString = String(leftBound.start.prefix(5))
let endTimeString = String(leftBound.end.prefix(5))
if inArr == 1 {
result.append("\(dayNumInString(leftBound.day)) \(startTimeString)-\(endTimeString))")
} else {
result.append("\(dayNumInString(leftBound.day))-\(dayNumInString(workTimes[i - 1].day)) \(startTimeString)-\(endTimeString)")
}
inArr = 1
leftBound = workTimes[i]
}
}
let startTimeString = String(leftBound.start.prefix(5))
let endTimeString = String(leftBound.end.prefix(5))
if inArr == 1 {
result.append("\(dayNumInString(leftBound.day)) \(startTimeString)-\(endTimeString)")
} else if inArr > 1, let leftBoundDayInt = Int(leftBound.day) {
result.append("\(dayNumInString(leftBound.day))-\(dayNumInString(workTimes[leftBoundDayInt + inArr - 2].day)) \(startTimeString)-\(endTimeString)")
}
return result
}
}