bunch of random work
This commit is contained in:
@@ -8,6 +8,20 @@
|
||||
import CoreData
|
||||
|
||||
extension PersistenceController {
|
||||
public func fixWrongWeekdays() {
|
||||
let data = PersistenceController.shared.getData(startDate: Date(timeIntervalSince1970: 0),
|
||||
endDate: Date(),
|
||||
includedDays: []).sorted(by: {
|
||||
$0.forDate! < $1.forDate!
|
||||
})
|
||||
|
||||
data.forEach({
|
||||
$0.weekDay = Int16(Calendar.current.component(.weekday, from: $0.forDate!.startOfDay))
|
||||
$0.forDate = $0.forDate?.startOfDay
|
||||
})
|
||||
try? viewContext.save()
|
||||
}
|
||||
|
||||
public func add(mood: Mood, forDate date: Date, entryType: EntryType) {
|
||||
if let existingEntry = getEntry(byDate: date) {
|
||||
viewContext.delete(existingEntry)
|
||||
@@ -18,7 +32,10 @@ extension PersistenceController {
|
||||
newItem.timestamp = Date()
|
||||
newItem.moodValue = Int16(mood.rawValue)
|
||||
newItem.forDate = date
|
||||
newItem.weekDay = Int16(Calendar.current.component(.weekday, from: date))
|
||||
|
||||
let localTime = date.toLocalTime()
|
||||
newItem.weekDay = Int16(Calendar.current.component(.weekday, from: localTime))
|
||||
|
||||
newItem.canEdit = true
|
||||
newItem.canDelete = true
|
||||
newItem.entryType = Int16(entryType.rawValue)
|
||||
|
||||
Reference in New Issue
Block a user