Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private func showMergeBtn(at index: Int, mergeUp: Bool) -> Bool {
- if (index == 0 && mergeUp) || (index == self.overtimeList.count - 1 && !mergeUp) {
- return false
- }
- let subtractIndex = mergeUp ? -1 : 1
- if let firstRequest = self.overtimeList[safe: index], let secondRequest = self.overtimeList[safe: index + subtractIndex] {
- if firstRequest.beaconStayLogId.isEmpty() || secondRequest.beaconStayLogId.isEmpty() {return false}
- if mergeUp {
- return !checkCoveredTimeSpace(checkDuration: (convertToInt(secondRequest.endTime), convertToInt(firstRequest.startTime)), durationArray: self.otRequest?.workingTimeDurations)
- } else {
- return !checkCoveredTimeSpace(checkDuration: (convertToInt(firstRequest.endTime), convertToInt(secondRequest.startTime)), durationArray: self.otRequest?.workingTimeDurations)
- }
- }
- return false
- }
- private func checkCoveredTimeSpace(checkDuration: (Int?, Int?), durationArray: [WorkingTimeDurations]?) -> Bool {
- guard let durationList = durationArray, !durationList.isEmpty else {return false}
- for duration in durationList {
- if checkTimeInDuration(time: checkDuration.0, duration: duration) || checkTimeInDuration(time: checkDuration.1, duration: duration) {
- return true
- }
- }
- return false
- }
- private func checkTimeInDuration(time: Int?, duration: WorkingTimeDurations) -> Bool {
- guard let time = time else {return false}
- return time >= (duration.start ?? 0) && time <= (duration.end ?? 0)
- }
- private func convertToInt(_ str: String?) -> Int {
- guard let timeString = str else {return 0}
- let hourRange = 0...1
- let minuteRange = 3...4
- let hour = Int(timeString[hourRange] ?? "01") ?? 01
- let minute = Int(timeString[minuteRange] ?? "01") ?? 01
- return (hour*60 + minute)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement