Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.00 KB | None | 0 0
  1.     private func showMergeBtn(at index: Int, mergeUp: Bool) -> Bool {
  2.         if (index == 0 && mergeUp) || (index == self.overtimeList.count - 1 && !mergeUp) {
  3.             return false
  4.            
  5.         }
  6.         let subtractIndex = mergeUp ? -1 : 1
  7.         if let firstRequest = self.overtimeList[safe: index], let secondRequest = self.overtimeList[safe: index + subtractIndex] {
  8.             if firstRequest.beaconStayLogId.isEmpty() || secondRequest.beaconStayLogId.isEmpty() {return false}
  9.             if mergeUp {
  10.                 return !checkCoveredTimeSpace(checkDuration: (convertToInt(secondRequest.endTime), convertToInt(firstRequest.startTime)), durationArray: self.otRequest?.workingTimeDurations)
  11.             } else {
  12.                 return !checkCoveredTimeSpace(checkDuration: (convertToInt(firstRequest.endTime), convertToInt(secondRequest.startTime)), durationArray: self.otRequest?.workingTimeDurations)
  13.             }
  14.         }
  15.         return false
  16.     }
  17. private func checkCoveredTimeSpace(checkDuration: (Int?, Int?), durationArray: [WorkingTimeDurations]?) -> Bool {
  18.         guard let durationList = durationArray, !durationList.isEmpty else {return false}
  19.         for duration in durationList {
  20.             if checkTimeInDuration(time: checkDuration.0, duration: duration) || checkTimeInDuration(time: checkDuration.1, duration: duration) {
  21.                 return true
  22.             }
  23.         }
  24.         return false
  25.     }
  26.    
  27.     private func checkTimeInDuration(time: Int?, duration: WorkingTimeDurations) -> Bool {
  28.         guard let time = time else {return false}
  29.         return time >= (duration.start ?? 0) && time <= (duration.end ?? 0)
  30.     }
  31. private func convertToInt(_ str: String?) -> Int {
  32.         guard let timeString = str else {return 0}
  33.         let hourRange = 0...1
  34.         let minuteRange = 3...4
  35.        
  36.         let hour =  Int(timeString[hourRange] ?? "01") ?? 01
  37.         let minute = Int(timeString[minuteRange] ?? "01") ?? 01
  38.         return (hour*60 + minute)
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement