Skip to content

Commit

Permalink
use calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
mltbnz committed Mar 1, 2024
1 parent ece2cf3 commit b89688e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CriticalMapsKit/Sources/NextRideFeature/NextRideCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public struct NextRideFeature: ReducerProtocol {
@Dependency(\.mainQueue) public var mainQueue
@Dependency(\.coordinateObfuscator) public var coordinateObfuscator
@Dependency(\.isNetworkAvailable) public var isNetworkAvailable
@Dependency(\.calendar) public var calendar

public struct State: Equatable {
public init(nextRide: Ride? = nil) {
Expand Down Expand Up @@ -70,6 +71,7 @@ public struct NextRideFeature: ReducerProtocol {
case let .nextRideResponse(.failure(error)):
logger.error("Get next ride failed 🛑 with error: \(error)")
return .none

case let .nextRideResponse(.success(rides)):
guard !rides.isEmpty else {
logger.info("Rides array is empty")
Expand Down Expand Up @@ -101,7 +103,7 @@ public struct NextRideFeature: ReducerProtocol {
return byDate
}

if Calendar.current.isDate(lhs.dateTime, inSameDayAs: rhs.dateTime) {
if calendar.isDate(lhs.dateTime, inSameDayAs: rhs.dateTime) {
return lhsCoordinate.distance(from: userLocation) < rhsCoordinate.distance(from: userLocation)
} else {
return byDate
Expand All @@ -113,7 +115,6 @@ public struct NextRideFeature: ReducerProtocol {
logger.info("No upcoming events after filter")
return .none
}

return EffectTask(value: .setNextRide(filteredRide))

case let .setNextRide(ride):
Expand Down

0 comments on commit b89688e

Please sign in to comment.