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

@@ -95,7 +95,7 @@ struct SettingsView: View {
guard let selectedFile: URL = try result.get().first else { return }
if selectedFile.startAccessingSecurityScopedResource() {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss +0000"
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
guard let input = String(data: try Data(contentsOf: selectedFile), encoding: .utf8) else { return }
@@ -104,7 +104,8 @@ struct SettingsView: View {
var rows = input.components(separatedBy: "\n")
rows.removeFirst()
for row in rows {
let columns = row.components(separatedBy: ",")
let stripped = row.replacingOccurrences(of: " +0000", with: "")
let columns = stripped.components(separatedBy: ",")
if columns.count != 7 {
continue
}
@@ -112,13 +113,13 @@ struct SettingsView: View {
moodEntry.canDelete = Bool(columns[0])!
moodEntry.canEdit = Bool(columns[1])!
moodEntry.entryType = Int16(columns[2])!
moodEntry.forDate = dateFormatter.date(from: columns[3])
moodEntry.forDate = dateFormatter.date(from: columns[3])!
moodEntry.moodValue = Int16(columns[4])!
moodEntry.timestamp = dateFormatter.date(from: columns[5])
moodEntry.timestamp = dateFormatter.date(from: columns[5])!
let localTime = dateFormatter.date(from: columns[3])!.toLocalTime()
let localTime = dateFormatter.date(from: columns[3])!
moodEntry.weekDay = Int16(Calendar.current.component(.weekday, from: localTime))
// let _ = print("import info: ", columns[3], dateFormatter.date(from: columns[3]), localTime, Int16(Calendar.current.component(.weekday, from: localTime)))
try! PersistenceController.shared.viewContext.save()
}
PersistenceController.shared.saveAndRunDataListerners()
@@ -508,7 +509,7 @@ struct TextFile: FileDocument {
let weekDay = entry.weekDay
let dataString = "\(canDelete),\(canEdit),\(entryType),\(String(describing: forDate)),\(moodValue),\(String(describing:timestamp)),\(weekDay)\n"
print("DATA: \(dataString)")
// print("DATA: \(dataString)")
csvString = csvString.appending(dataString)
}
text = csvString