bunch of random work

This commit is contained in:
Trey t
2022-04-03 20:20:12 -05:00
parent 9d008236bc
commit dec8f2d84d
7 changed files with 100 additions and 32 deletions

View File

@@ -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
}
}