This commit is contained in:
Trey t
2022-01-15 12:15:26 -06:00
parent b7bb06ddad
commit ef4cc2f159
2 changed files with 16 additions and 12 deletions

View File

@@ -74,12 +74,22 @@ struct PersistenceController {
return last ?? nil
}
public func getData(startDate: Date, endDate: Date) -> [MoodEntry] {
let predicate = NSPredicate(format: "%K >= %@ && %K <= %@",
public func getData(startDate: Date, endDate: Date, includedDays: [Int]) -> [MoodEntry] {
var includedDays16 = [Int16]()
if includedDays.isEmpty {
includedDays16 = [Int16(1), Int16(2), Int16(3), Int16(4), Int16(5), Int16(6), Int16(7)]
} else {
includedDays16 = includedDays.map({
Int16($0)
})
}
let predicate = NSPredicate(format: "%K >= %@ && %K <= %@ && weekDay IN %@",
"forDate",
startDate as NSDate,
"forDate",
endDate as NSDate)
endDate as NSDate,
includedDays16)
let fetchRequest = NSFetchRequest<MoodEntry>(entityName: "MoodEntry")
fetchRequest.predicate = predicate