Skip to content
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
4 changes: 2 additions & 2 deletions Uplift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@
2EE5F3E02B12EDB6008E0299 /* XCRemoteSwiftPackageReference "apollo-ios" */,
2E6785BA2B3A48D700DD3ADA /* XCRemoteSwiftPackageReference "WrappingHStack" */,
2EC3EE642B3C000E00E927BF /* XCRemoteSwiftPackageReference "Kingfisher" */,
2E4F06DA2B4B48DC008905C8 /* XCLocalSwiftPackageReference "UpliftAPI" */,
2E45B23E2B4E361100FB83B7 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
2EE5D6512B65E7DC004BB8F5 /* XCRemoteSwiftPackageReference "appdev-announcements" */,
89ED9AE92B9D76EA00995941 /* XCLocalSwiftPackageReference "UpliftAPI" */,
);
productRefGroup = 2E8FE38D2B1278B700B3DC6A /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -991,7 +991,7 @@
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
2E4F06DA2B4B48DC008905C8 /* XCLocalSwiftPackageReference "UpliftAPI" */ = {
89ED9AE92B9D76EA00995941 /* XCLocalSwiftPackageReference "UpliftAPI" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = UpliftAPI;
};
Expand Down
3 changes: 2 additions & 1 deletion Uplift.xcworkspace/xcshareddata/swiftpm/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions Uplift/Models/Gym.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,66 @@ struct Gym: Hashable {
facilities.filter { $0.facilityType != .fitness }
}

/**
Determine whether at least one fitness center is open at this `Gym` depending on its fitness centers' hours.

- Parameters:
- currentTime: The current time to compare with and determine the status. Default is now.

- Returns: A `Bool` representing whether at least one of its fitness centers is open.
*/
func fitnessCenterIsOpen(currentTime: Date = Date.now) -> Bool {
fitnessCenters.contains {
switch $0.hours.getStatus(currentTime: currentTime) {
case .open:
return true
default:
return false
}
}
}

/**
Retrieve the status of the `Gym` depending on the fitness centers' hours.

- Parameters:
- currentTime: The current time to compare with and determine the status. Default is now.

- Returns: A `Status` object based on its fitness centers' hours. `nil` if there are no open or close hours in the future.
*/
func determineStatus(currentTime: Date = Date.now) -> Status? {
if fitnessCenterIsOpen(currentTime: currentTime) {
// Get all possible close times
let closeTimes = fitnessCenters.compactMap {
switch $0.hours.getStatus(currentTime: currentTime) {
case .open(let closeTime):
return closeTime
default:
return nil
}
}

// Get the latest closing time
if let closeTime = closeTimes.max() {
return Status.open(closeTime: closeTime)
}
} else {
// Get all possible open times
let openTimes = fitnessCenters.compactMap {
switch $0.hours.getStatus(currentTime: currentTime) {
case .closed(let openTime):
return openTime
default:
return nil
}
}

// Get the earliest open time
if let openTime = openTimes.min() {
return Status.closed(openTime: openTime)
}
}
return nil
}

}
Loading