From 44b0077a60a7f5266b0d7c57feb20ae514a31e19 Mon Sep 17 00:00:00 2001 From: PaulGarewal Date: Fri, 17 Jan 2025 10:53:20 -0800 Subject: [PATCH] feat: overnight shift handler as well as validation message confirmation --- .github/workflows/main.yaml | 2 +- ipad.xcodeproj/project.pbxproj | 4 +-- ipad/Models/Shift/ShiftModel.swift | 29 +++++++++++++++++-- .../Shift/ShiftViewController.swift | 5 +++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c32ef19..af46ea0 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -15,7 +15,7 @@ jobs: ARCHIVE_NAME: ${{ 'invasivesbc-mussels.iOS.xcarchive' }} EXPORT_DIR: ${{ 'export' }} IPA_NAME: ${{ 'invasivesbc-mussels.iOS.ipa' }} - APP_BUILD_VERSION: "2.7.5" + APP_BUILD_VERSION: "2.7.6" steps: - uses: maxim-lobanov/setup-xcode@v1 diff --git a/ipad.xcodeproj/project.pbxproj b/ipad.xcodeproj/project.pbxproj index f8cb4cd..650a740 100644 --- a/ipad.xcodeproj/project.pbxproj +++ b/ipad.xcodeproj/project.pbxproj @@ -2063,7 +2063,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 2.8.7; + MARKETING_VERSION = 2.8.8; PRODUCT_BUNDLE_IDENTIFIER = ca.bc.gov.InvasivesBC; PRODUCT_NAME = Inspect; PROVISIONING_PROFILE_SPECIFIER = "InvasivesBC Muscles - 2023/24"; @@ -2093,7 +2093,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 2.8.7; + MARKETING_VERSION = 2.8.8; PRODUCT_BUNDLE_IDENTIFIER = ca.bc.gov.InvasivesBC; PRODUCT_NAME = Inspect; PROVISIONING_PROFILE_SPECIFIER = "InvasivesBC Muscles - 2023/24"; diff --git a/ipad/Models/Shift/ShiftModel.swift b/ipad/Models/Shift/ShiftModel.swift index 751e6b3..b37c367 100644 --- a/ipad/Models/Shift/ShiftModel.swift +++ b/ipad/Models/Shift/ShiftModel.swift @@ -241,6 +241,26 @@ class ShiftModel: Object, BaseRealmObject { return .Draft } } + // Determine if shift is overnight + func isOvernightShift() -> Bool { + let startTime = self.startTime.components(separatedBy: ":") + let endTime = self.endTime.components(separatedBy: ":") + + guard startTime.count == 2, endTime.count == 2, + let startHour = Int(startTime[0]), + let endHour = Int(endTime[0]), + let startMinute = Int(startTime[1]), + let endMinute = Int(endTime[1]) else { + return false + } + + if startHour == endHour { + if endMinute < startMinute { + return true + } + } + return startHour > endHour + } /// Formats a Date object with a Time String into a readable format /// - Parameters: /// - time: String object representing time in "HH:mm" format (e.g. "10:42") @@ -262,8 +282,13 @@ class ShiftModel: Object, BaseRealmObject { var calendar = Calendar.current calendar.timeZone = ShiftModel.getTimezoneForStation(self.station) - // Create components in station's timezone - var components = calendar.dateComponents([.year, .month, .day], from: date) + // If shift is overnight and this is the end time, add a day + var targetDate = date + if time == endTime && isOvernightShift() { + targetDate = calendar.date(byAdding: .day, value: 1, to: date) ?? date + } + + var components = calendar.dateComponents([.year, .month, .day], from: targetDate) components.hour = hour components.minute = minute components.second = 1 diff --git a/ipad/ViewControllers/Shift/ShiftViewController.swift b/ipad/ViewControllers/Shift/ShiftViewController.swift index 6395a44..5b54111 100644 --- a/ipad/ViewControllers/Shift/ShiftViewController.swift +++ b/ipad/ViewControllers/Shift/ShiftViewController.swift @@ -198,7 +198,10 @@ class ShiftViewController: BaseViewController { // if can submit var alertMessage = "This shift and the inspections will be uploaded when possible" if model.shiftStartDate < Calendar.current.startOfDay(for: Date()) { - alertMessage += "\n\n You've entered a date that occurred before today. If this was intentional, no problem! Otherwise, please double-check the entered date: \n\(model.shiftStartDate.stringShort())" + alertMessage += "\n\n 🔵 You've entered a date that occurred before today. If this was intentional, no problem! Otherwise, please double-check the entered date: \n\(model.shiftStartDate.stringShort())" + } + if model.isOvernightShift() { + alertMessage += "\n\n 🔵 You've entered an overnight shift. This shift will carry over to the next day. If this was intentional, no problem! Otherwise, please double-check the entered shift times. \n" } if canSubmit() && model.inspections.allSatisfy({ $0.formDidValidate }) { Alert.show(title: "Are you sure?", message: alertMessage, yes: {[weak self] in