change a bunch of shit to get importing / adding new vote have the right weekday

This commit is contained in:
Trey t
2022-04-05 22:33:12 -05:00
parent dec8f2d84d
commit 6fa4e2db26
17 changed files with 141 additions and 190 deletions

View File

@@ -16,8 +16,7 @@ extension PersistenceController {
})
data.forEach({
$0.weekDay = Int16(Calendar.current.component(.weekday, from: $0.forDate!.startOfDay))
$0.forDate = $0.forDate?.startOfDay
$0.weekDay = Int16(Calendar.current.component(.weekday, from: $0.forDate!))
})
try? viewContext.save()
}
@@ -32,10 +31,7 @@ extension PersistenceController {
newItem.timestamp = Date()
newItem.moodValue = Int16(mood.rawValue)
newItem.forDate = date
let localTime = date.toLocalTime()
newItem.weekDay = Int16(Calendar.current.component(.weekday, from: localTime))
newItem.weekDay = Int16(Calendar.current.component(.weekday, from: date))
newItem.canEdit = true
newItem.canDelete = true
newItem.entryType = Int16(entryType.rawValue)
@@ -47,7 +43,9 @@ extension PersistenceController {
func fillInMissingDates() {
let currentOnboarding = UserDefaultsStore.getOnboarding()
let endDate = ShowBasedOnVoteLogics.getLastDateVoteShouldExist(onboardingData: currentOnboarding)
var endDate = ShowBasedOnVoteLogics.getCurrentVotingDate(onboardingData: currentOnboarding)
// since its for views take away the last date so vote is enabled
endDate = Calendar.current.date(byAdding: .day, value: -1, to: endDate)!
let fetchRequest = NSFetchRequest<MoodEntry>(entityName: "MoodEntry")
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "forDate", ascending: false)]