Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INSPECT-335][FEATURE] - Overnight Shift Calendar Increment #349

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ipad.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
29 changes: 27 additions & 2 deletions ipad/Models/Shift/ShiftModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion ipad/ViewControllers/Shift/ShiftViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading