@@ -11,6 +11,7 @@ final class BookingListViewModel: ObservableObject {
1111 private let type : BookingListTab
1212 private let stores : StoresManager
1313 private let storage : StorageManagerType
14+ private let currentDate : Date
1415
1516 private static let refreshCacheReason = " refresh-cache "
1617
@@ -27,10 +28,10 @@ final class BookingListViewModel: ObservableObject {
2728 /// Booking ResultsController.
2829 private lazy var resultsController : ResultsController < StorageBooking > = {
2930 var predicates = [ NSPredicate ( format: " siteID == %lld " , siteID) ]
30- if let before = type. startDateBefore {
31+ if let before = type. startDateBefore ( currentDate : currentDate ) {
3132 predicates. append ( NSPredicate ( format: " startDate < %@ " , before as NSDate ) )
3233 }
33- if let after = type. startDateAfter {
34+ if let after = type. startDateAfter ( currentDate : currentDate ) {
3435 predicates. append ( NSPredicate ( format: " startDate > %@ " , after as NSDate ) )
3536 }
3637 let combinedPredicate = NSCompoundPredicate ( type: . and, subpredicates: predicates)
@@ -44,11 +45,13 @@ final class BookingListViewModel: ObservableObject {
4445 init ( siteID: Int64 ,
4546 type: BookingListTab ,
4647 stores: StoresManager = ServiceLocator . stores,
47- storage: StorageManagerType = ServiceLocator . storageManager) {
48+ storage: StorageManagerType = ServiceLocator . storageManager,
49+ currentDate: Date = Date ( ) ) {
4850 self . siteID = siteID
4951 self . type = type
5052 self . stores = stores
5153 self . storage = storage
54+ self . currentDate = currentDate
5255 self . paginationTracker = PaginationTracker ( pageFirstIndex: pageFirstIndex)
5356
5457 configureResultsController ( )
@@ -114,8 +117,8 @@ extension BookingListViewModel: PaginationTrackerDelegate {
114117 siteID: siteID,
115118 pageNumber: pageNumber,
116119 pageSize: pageSize,
117- startDateBefore: type. startDateBefore? . ISO8601Format ( ) ,
118- startDateAfter: type. startDateAfter? . ISO8601Format ( ) ,
120+ startDateBefore: type. startDateBefore ( currentDate : currentDate ) ? . ISO8601Format ( ) ,
121+ startDateAfter: type. startDateAfter ( currentDate : currentDate ) ? . ISO8601Format ( ) ,
119122 shouldClearCache: shouldClearCache
120123 ) { [ weak self] result in
121124 switch result {
0 commit comments