activeGoal(userId: String, time: Date) -> Observable<MeditationGoal> { let durationGoal = self .goalRepository .lastGoal(before: time.endOfLocalDay, type: .duration, userId: userId) let sessionsGoal = self .goalRepository .lastGoal(before: time.endOfLocalDay, type: .sessions, userId: userId) return Observable.combineLatest(durationGoal, sessionsGoal) { $0.time >= $1.time ? $0 : $1 } } func sessions(userId: String, date: Date) -> Observable<[MeditationSession]> { let startDate = date.beginningOfLocalDay let endDate = date.endOfLocalDay return self .sessionRepository .sessions(userId: userId, startDate: startDate, endDate: endDate) }