bunch of random work
This commit is contained in:
@@ -67,7 +67,6 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
|
||||
date = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
|
||||
}
|
||||
|
||||
|
||||
switch action {
|
||||
case .horrible:
|
||||
PersistenceController.shared.add(mood: .horrible, forDate: date, entryType: .notification)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -35,30 +35,64 @@ class ShowBasedOnVoteLogics {
|
||||
return (passedTimeToVote, inputDay)
|
||||
}
|
||||
|
||||
static func isMissingCurrentVote(onboardingData: OnboardingData) -> Bool {
|
||||
var startDate: Date?
|
||||
|
||||
static func getLastDateVoteShouldExistOnViews(onboardingData: OnboardingData) -> Date {
|
||||
var date: Date?
|
||||
|
||||
switch ShowBasedOnVoteLogics.returnCurrentVoteStatus(onboardingData: onboardingData) {
|
||||
case (false, .Today):
|
||||
// if we're NOT passed time to vote and the voting type is previous - last vote should be -1
|
||||
startDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
|
||||
// if we're passed time to vote and the voting type is previous - last vote should be -1
|
||||
date = Calendar.current.date(byAdding: .day, value: -2, to: Date())
|
||||
case (true, .Today):
|
||||
// if we're passed time to vote and the voting type is today - last vote should be current date
|
||||
startDate = Date()
|
||||
// if we're passed time to vote and the voting type is previous - last vote should be today
|
||||
date = Calendar.current.date(byAdding: .day, value: -1, to: Date())
|
||||
|
||||
case (false, .Previous):
|
||||
// if we're NOT passed time to vote and the voting type is previous - last vote should be 2 days ago
|
||||
startDate = Calendar.current.date(byAdding: .day, value: -2, to: Date())!
|
||||
// if we're passed time to vote and the voting type is previous - last vote should be -2
|
||||
date = Calendar.current.date(byAdding: .day, value: -3, to: Date())
|
||||
case (true, .Previous):
|
||||
// if we're passed time to vote and the voting type is previous - last vote should be -1
|
||||
startDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
|
||||
date = Calendar.current.date(byAdding: .day, value: -2, to: Date())
|
||||
}
|
||||
|
||||
guard let date = date else {
|
||||
fatalError("missing getCurrentVotingDate")
|
||||
}
|
||||
|
||||
startDate = Calendar.current.startOfDay(for: startDate!)
|
||||
let endDate = Calendar.current.date(byAdding: .day, value: 1, to: startDate!)!
|
||||
return date
|
||||
}
|
||||
|
||||
static func getCurrentVotingDate(onboardingData: OnboardingData) -> Date {
|
||||
var date: Date?
|
||||
|
||||
switch ShowBasedOnVoteLogics.returnCurrentVoteStatus(onboardingData: onboardingData) {
|
||||
case (false, .Today):
|
||||
// if we're passed time to vote and the voting type is previous - last vote should be -1
|
||||
date = Calendar.current.date(byAdding: .day, value: -1, to: Date())
|
||||
case (true, .Today):
|
||||
// if we're passed time to vote and the voting type is previous - last vote should be today
|
||||
date = Date()
|
||||
|
||||
case (false, .Previous):
|
||||
// if we're passed time to vote and the voting type is previous - last vote should be -2
|
||||
date = Calendar.current.date(byAdding: .day, value: -2, to: Date())
|
||||
case (true, .Previous):
|
||||
// if we're passed time to vote and the voting type is previous - last vote should be -1
|
||||
date = Calendar.current.date(byAdding: .day, value: -1, to: Date())
|
||||
}
|
||||
|
||||
guard let date = date else {
|
||||
fatalError("missing getCurrentVotingDate")
|
||||
}
|
||||
|
||||
return date
|
||||
}
|
||||
|
||||
static func isMissingCurrentVote(onboardingData: OnboardingData) -> Bool {
|
||||
let startDate = ShowBasedOnVoteLogics.getCurrentVotingDate(onboardingData: onboardingData).startOfDay
|
||||
let endDate = startDate.endOfDay
|
||||
|
||||
let fetchRequest = NSFetchRequest<MoodEntry>(entityName: "MoodEntry")
|
||||
let fromPredicate = NSPredicate(format: "%@ <= %K", startDate!
|
||||
let fromPredicate = NSPredicate(format: "%@ <= %K", startDate
|
||||
as NSDate, #keyPath(MoodEntry.forDate))
|
||||
let toPredicate = NSPredicate(format: "%K < %@", #keyPath(MoodEntry.forDate), endDate as NSDate)
|
||||
let datePredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [fromPredicate, toPredicate])
|
||||
@@ -83,6 +117,9 @@ class ShowBasedOnVoteLogics {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------delete---------------------------------------*/
|
||||
|
||||
static func dateForHeaderVote(onboardingData: OnboardingData) -> Date? {
|
||||
var date: Date?
|
||||
|
||||
@@ -108,7 +145,7 @@ class ShowBasedOnVoteLogics {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
static func getLastDateVoteShouldExist(onboardingData: OnboardingData) -> Date {
|
||||
var date: Date?
|
||||
|
||||
@@ -151,4 +188,6 @@ class ShowBasedOnVoteLogics {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@ struct DayFilterPickerView: View {
|
||||
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
|
||||
@StateObject private var filteredDays = DaysFilterClass.shared
|
||||
|
||||
let weekdays = [("Sun", 1),
|
||||
("mon", 2),
|
||||
("tue", 3),
|
||||
("wed", 4),
|
||||
("thur", 5),
|
||||
("fri", 6),
|
||||
("sat", 7)]
|
||||
let weekdays = [(Calendar.current.shortWeekdaySymbols[0], 1),
|
||||
(Calendar.current.shortWeekdaySymbols[1], 2),
|
||||
(Calendar.current.shortWeekdaySymbols[2], 3),
|
||||
(Calendar.current.shortWeekdaySymbols[3], 4),
|
||||
(Calendar.current.shortWeekdaySymbols[4], 5),
|
||||
(Calendar.current.shortWeekdaySymbols[5], 6),
|
||||
(Calendar.current.shortWeekdaySymbols[6], 7)]
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
|
||||
@@ -320,13 +320,6 @@ struct ViewOffsetKey: PreferenceKey {
|
||||
}
|
||||
}
|
||||
|
||||
private let itemFormatter: DateFormatter = {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .short
|
||||
formatter.timeStyle = .medium
|
||||
return formatter
|
||||
}()
|
||||
|
||||
struct DayView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
DayView(viewModel: DayViewViewModel(addMonthStartWeekdayPadding: false)).environment(\.managedObjectContext, PersistenceController.shared.viewContext)
|
||||
|
||||
@@ -204,6 +204,7 @@ extension MonthView {
|
||||
LazyVGrid(columns: columns, spacing: 15) {
|
||||
ForEach(entries, id: \.self) { entry in
|
||||
if filteredDays.currentFilters.contains(Int(entry.weekDay)) {
|
||||
let _ = print(entry.weekDay, entry.forDate, filteredDays.currentFilters, entry.id)
|
||||
shape.view(withText: Text(""),
|
||||
bgColor: entry.mood == .placeholder ? .clear : moodTint.color(forMood: entry.mood),
|
||||
textColor: .clear)
|
||||
|
||||
@@ -50,7 +50,7 @@ struct SettingsView: View {
|
||||
if useCloudKit {
|
||||
cloudKitStatus
|
||||
}
|
||||
|
||||
fixWeekday
|
||||
exportData
|
||||
importData
|
||||
Divider()
|
||||
@@ -96,6 +96,7 @@ struct SettingsView: View {
|
||||
if selectedFile.startAccessingSecurityScopedResource() {
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss +0000"
|
||||
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
|
||||
|
||||
guard let input = String(data: try Data(contentsOf: selectedFile), encoding: .utf8) else { return }
|
||||
defer { selectedFile.stopAccessingSecurityScopedResource() }
|
||||
@@ -114,7 +115,10 @@ struct SettingsView: View {
|
||||
moodEntry.forDate = dateFormatter.date(from: columns[3])
|
||||
moodEntry.moodValue = Int16(columns[4])!
|
||||
moodEntry.timestamp = dateFormatter.date(from: columns[5])
|
||||
moodEntry.weekDay = Int16(columns[6])!
|
||||
|
||||
let localTime = dateFormatter.date(from: columns[3])!.toLocalTime()
|
||||
moodEntry.weekDay = Int16(Calendar.current.component(.weekday, from: localTime))
|
||||
|
||||
try! PersistenceController.shared.viewContext.save()
|
||||
}
|
||||
PersistenceController.shared.saveAndRunDataListerners()
|
||||
@@ -208,6 +212,21 @@ struct SettingsView: View {
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
private var fixWeekday: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
Button(action: {
|
||||
PersistenceController.shared.fixWrongWeekdays()
|
||||
}, label: {
|
||||
Text("Fix Weekday")
|
||||
.foregroundColor(textColor)
|
||||
})
|
||||
.padding()
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
private var whyBackgroundMode: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
|
||||
Reference in New Issue
Block a user