hopefully fix issue where voting is filled in with missing when its time to vote

This commit is contained in:
Trey t
2022-03-05 11:28:29 -06:00
parent 012fcc43d5
commit d56e74053e
13 changed files with 168 additions and 105 deletions

View File

@@ -50,6 +50,8 @@
1C361F1127C03C3D00E832FC /* OnboardingTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CA03772279A293D00D26164 /* OnboardingTime.swift */; };
1C361F1427C03C8600E832FC /* OnboardingDataDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C361F1327C03C8600E832FC /* OnboardingDataDataManager.swift */; };
1C361F1727C046D800E832FC /* MonthDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C361F1627C046D800E832FC /* MonthDetailView.swift */; };
1C414BF127D3CAB300BC1720 /* OnboardingData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5F4975279C84090092F1B4 /* OnboardingData.swift */; };
1C414BF527D3CB2200BC1720 /* OnboardingDay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CA03774279A294800D26164 /* OnboardingDay.swift */; };
1C4FF3BB27BEDDF000BE8F34 /* ShowBasedOnVoteLogics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4FF3BA27BEDDF000BE8F34 /* ShowBasedOnVoteLogics.swift */; };
1C4FF3BC27BEDF6600BE8F34 /* ShowBasedOnVoteLogics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4FF3BA27BEDDF000BE8F34 /* ShowBasedOnVoteLogics.swift */; };
1C4FF3BE27BEDF9100BE8F34 /* PersistenceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4FF3BD27BEDF9100BE8F34 /* PersistenceHelper.swift */; };
@@ -66,7 +68,6 @@
1C658D7827C0744D003231EE /* PersistenceUPDATE.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C658D7627C0744D003231EE /* PersistenceUPDATE.swift */; };
1C683FCA2792281400745862 /* Stats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C683FC92792281400745862 /* Stats.swift */; };
1C683FCB2792281400745862 /* Stats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C683FC92792281400745862 /* Stats.swift */; };
1C683FCC2792281400745862 /* Stats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C683FC92792281400745862 /* Stats.swift */; };
1C744F2C278CE15600953A57 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C744F2B278CE15600953A57 /* AppDelegate.swift */; };
1C747CC9279F06EB00762CBD /* CloudKitSyncMonitor in Frameworks */ = {isa = PBXBuildFile; productRef = 1C747CC8279F06EB00762CBD /* CloudKitSyncMonitor */; };
1C76E86E27C882A400ADEE1F /* SharingImageModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C76E86D27C882A400ADEE1F /* SharingImageModels.swift */; };
@@ -111,7 +112,6 @@
1CD90B53278C7E7A001C4FEA /* FeelsWidget.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B4E278C7E7A001C4FEA /* FeelsWidget.intentdefinition */; };
1CD90B56278C7E7A001C4FEA /* FeelsWidgetExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 1CD90B45278C7E7A001C4FEA /* FeelsWidgetExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
1CD90B5D278C7EAD001C4FEA /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B5C278C7EAD001C4FEA /* Random.swift */; };
1CD90B5E278C7EAD001C4FEA /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B5C278C7EAD001C4FEA /* Random.swift */; };
1CD90B5F278C7EAD001C4FEA /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B5C278C7EAD001C4FEA /* Random.swift */; };
1CD90B63278C7EBA001C4FEA /* Mood.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B61278C7EBA001C4FEA /* Mood.swift */; };
1CD90B64278C7EBA001C4FEA /* Mood.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B61278C7EBA001C4FEA /* Mood.swift */; };
@@ -855,7 +855,6 @@
1CD90B64278C7EBA001C4FEA /* Mood.swift in Sources */,
1CD90B17278C7DE0001C4FEA /* Feels.xcdatamodeld in Sources */,
1CD90B67278C7EBA001C4FEA /* MoodEntryExtension.swift in Sources */,
1CD90B5E278C7EAD001C4FEA /* Random.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -863,9 +862,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1C414BF127D3CAB300BC1720 /* OnboardingData.swift in Sources */,
1CD90B09278C7DE0001C4FEA /* Tests_iOSLaunchTests.swift in Sources */,
1C683FCC2792281400745862 /* Stats.swift in Sources */,
1CD90B07278C7DE0001C4FEA /* Tests_iOS.swift in Sources */,
1C414BF527D3CB2200BC1720 /* OnboardingDay.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1076,7 +1076,7 @@
CODE_SIGN_ENTITLEMENTS = "Feels (iOS)Dev.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = V3PF3M6B6U;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
@@ -1112,7 +1112,7 @@
CODE_SIGN_ENTITLEMENTS = "Feels (iOS).entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = V3PF3M6B6U;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;

View File

@@ -32,7 +32,7 @@ struct TimeLineCreator {
var timeLineView = [WatchTimelineView]()
var startDayOffset = 0
if !UserDefaultsStore.getOnboarding().ableToVoteBasedOnCurentTime() {
if !ShowBasedOnVoteLogics.ableToVoteBasedOnCurentTime(voteDate: UserDefaultsStore.getOnboarding().date) {
startDayOffset = 1
}

View File

@@ -16,6 +16,7 @@ class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// PersistenceController.shared.clearDB()
// PersistenceController.shared.deleteLast(numberOfEntries: 5)
PersistenceController.shared.removeNoForDates()
PersistenceController.shared.fillInMissingDates()
UNUserNotificationCenter.current().delegate = self

View File

@@ -56,15 +56,25 @@ extension Date: RawRepresentable {
Calendar.current.dateComponents([.calendar, .year,.month], from: self).date!
}
static func dates(from fromDate: Date, to toDate: Date) -> [Date] {
static public func dates(from fromDate: Date, toDate: Date, includingToDate: Bool = false) -> [Date] {
var dates: [Date] = []
var date = fromDate
var date = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: fromDate)!
let toDate = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: toDate)!
while date <= toDate {
dates.append(date)
guard let newDate = Calendar.current.date(byAdding: .day, value: 1, to: date) else { break }
date = newDate
if includingToDate {
while date <= toDate {
dates.append(date)
guard let newDate = Calendar.current.date(byAdding: .day, value: 1, to: date) else { break }
date = newDate
}
} else {
while date < toDate {
dates.append(date)
guard let newDate = Calendar.current.date(byAdding: .day, value: 1, to: date) else { break }
date = newDate
}
}
return dates
}

View File

@@ -41,7 +41,7 @@ class MoodEntryFunctions {
var startOfMonth = date.startOfMonth
startOfMonth = Calendar.current.date(byAdding: .hour, value: 9, to: startOfMonth)!
let lastMissingDate = mutableEntries.first?.forDate ?? date.endOfMonth
var missingDates = Date.dates(from: startOfMonth, to: lastMissingDate)
var missingDates = Date.dates(from: startOfMonth, toDate: lastMissingDate, includingToDate: true)
missingDates = missingDates.dropLast()
for date in missingDates {

View File

@@ -31,28 +31,7 @@ final class OnboardingData: NSObject, ObservableObject, Codable {
date = try container.decode(Date.self, forKey: .date)
inputDay = try container.decode(DayOptions.self, forKey: .inputDay)
}
func ableToVoteBasedOnCurentTime() -> Bool {
let currentDateComp = Calendar.current.dateComponents([.hour, .minute], from: Date())
let savedDateComp = Calendar.current.dateComponents([.hour, .minute], from: self.date)
if let currentHour = currentDateComp.hour,
let currentMin = currentDateComp.minute,
let savedHour = savedDateComp.hour,
let savedMin = savedDateComp.minute {
if currentHour > savedHour {
return true
}
if currentHour == savedHour {
return currentMin >= savedMin
}
}
return false
}
override init() { }
}

View File

@@ -35,7 +35,7 @@ extension PersistenceController {
let entries = try! viewContext.fetch(fetchRequest)
if let firstEntry = entries.last?.forDate {
let allDates: [Date] = Date.dates(from: firstEntry, to: endDate).map({
let allDates: [Date] = Date.dates(from: firstEntry, toDate: endDate, includingToDate: true).map({
let zeroDate = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: $0)!
return zeroDate
})

View File

@@ -19,4 +19,14 @@ extension PersistenceController {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
}
func deleteLast(numberOfEntries: Int) {
let entries = PersistenceController.shared.getData(startDate: Calendar.current.date(byAdding: .day, value: -numberOfEntries, to: Date())!,
endDate: Date(),
includedDays: [])
for entry in entries {
viewContext.delete(entry)
}
try! viewContext.save()
}
}

View File

@@ -189,3 +189,21 @@ extension UIColor {
return self
}
}
extension Bundle {
var appName: String {
return infoDictionary?["CFBundleName"] as! String
}
var bundleId: String {
return bundleIdentifier!
}
var versionNumber: String {
return infoDictionary?["CFBundleShortVersionString"] as! String
}
var buildNumber: String {
return infoDictionary?["CFBundleVersion"] as! String
}
}

View File

@@ -9,33 +9,48 @@ import CoreData
import SwiftUI
//if this is being shown we're missing an entry
// voting time is noon
// vote for current day
// today at 11 am -> How as yesterday
// today at 1 pm -> How is today
// vote for previous day
// today at 11 am -> How as 2 days ago
// today at 1 pm -> How was yesterday
/*
current day 3/5/22
day option = .today
-------
voting for 3/4 | voting for 3/5
------------------------*-------------------------
db should contain 3/3 | db should contain 3/4
----------------------------------------------------------------------------
day option = .yesterday
--------
voting for 3/3 | voting for 3/4
------------------------*-------------------------
db should contain 3/2 | db should contain 3/3
*/
class ShowBasedOnVoteLogics {
static func isMissingCurrentVote(onboardingData: OnboardingData) -> Bool {
let passedTimeToVote = onboardingData.ableToVoteBasedOnCurentTime()
let inputDay = onboardingData.inputDay
static func returnCurrentVoteStatus(onboardingData: OnboardingData) -> (Bool, DayOptions) {
let passedTimeToVote = ShowBasedOnVoteLogics.ableToVoteBasedOnCurentTime(voteDate: onboardingData.date)
let inputDay: DayOptions = onboardingData.inputDay
return (passedTimeToVote, inputDay)
}
static func isMissingCurrentVote(onboardingData: OnboardingData) -> Bool {
var startDate: Date?
switch (passedTimeToVote, inputDay) {
case (true, .Previous):
// if we're passed time to vote and the voting type is previous - last vote should be -1
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())!
case (true, .Today):
// if we're passed time to vote and the voting type is today - last vote should be current date
startDate = 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())!
case (false, .Today):
// if we're NOT passed time to vote and the voting type is previous - last vote should be -1
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())!
}
@@ -54,43 +69,35 @@ class ShowBasedOnVoteLogics {
}
static func getVotingTitle(onboardingData: OnboardingData) -> String {
let passedTimeToVote = onboardingData.ableToVoteBasedOnCurentTime()
let inputDay = onboardingData.inputDay
switch (passedTimeToVote, inputDay) {
case (true, .Previous):
// if we're passed time to vote and the voting type is previous - last vote should be -1
return "how was yesterday"
case (true, .Today):
// if we're passed time to vote and the voting type is previous - last vote should be today
return "how is today"
case (false, .Previous):
// if we're passed time to vote and the voting type is previous - last vote should be -2
let lastDayVoteShouldExist = ShowBasedOnVoteLogics.getLastDateVoteShouldExist(onboardingData: onboardingData)
return "how was \(Random.weekdayName(fromDate: lastDayVoteShouldExist))"
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
return "how as yesterday"
case (true, .Today):
return "how is today"
case (false, .Previous):
let date = Calendar.current.date(byAdding: .day, value: -2, to: Date())!
return "how was \(Random.weekdayName(fromDate: date))"
case (true, .Previous):
return "how was yesterday"
}
}
static func dateForHeaderVote(onboardingData: OnboardingData) -> Date? {
let passedTimeToVote = onboardingData.ableToVoteBasedOnCurentTime()
let inputDay = onboardingData.inputDay
var date: Date?
switch (passedTimeToVote, inputDay) {
case (true, .Previous):
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 (false, .Today):
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())
}
@@ -103,26 +110,45 @@ class ShowBasedOnVoteLogics {
}
static func getLastDateVoteShouldExist(onboardingData: OnboardingData) -> Date {
let passedTimeToVote = onboardingData.ableToVoteBasedOnCurentTime()
let inputDay = onboardingData.inputDay
var date: Date?
var endDate: Date?
switch (passedTimeToVote, inputDay) {
case (true, .Previous):
// if we're passed time to vote and the voting type is previous - last vote should -1
endDate = 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
endDate = Date()
case (false, .Previous):
// if we're passed time to vote and the voting type is previous - last vote should be -2
endDate = Calendar.current.date(byAdding: .day, value: -2, to: 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 -2
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 previous - last vote should be -1
endDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
date = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
case (false, .Previous):
// if we're passed time to vote and the voting type is previous - last vote should be -3
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 -2
date = Calendar.current.date(byAdding: .day, value: -2, to: Date())!
}
return endDate!
return date!
}
static func ableToVoteBasedOnCurentTime(voteDate: Date) -> Bool {
let currentDateComp = Calendar.current.dateComponents([.hour, .minute], from: Date())
let savedDateComp = Calendar.current.dateComponents([.hour, .minute], from: voteDate)
if let currentHour = currentDateComp.hour,
let currentMin = currentDateComp.minute,
let savedHour = savedDateComp.hour,
let savedMin = savedDateComp.minute {
if currentHour > savedHour {
return true
}
if currentHour == savedHour {
return currentMin >= savedMin
}
}
return false
}
}

View File

@@ -33,6 +33,7 @@ struct SettingsView: View {
showOnboardingButton
whyBackgroundMode
specialThanksCell
}
Group {
@@ -44,6 +45,9 @@ struct SettingsView: View {
}
}
Spacer()
Text("\(Bundle.main.appName) v \(Bundle.main.versionNumber) (Build \(Bundle.main.buildNumber))")
.font(.body)
}
.padding()
}.sheet(isPresented: $showOnboarding) {

View File

@@ -6,9 +6,9 @@
//
import XCTest
@testable import iFeel
class Tests_iOS: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
@@ -22,21 +22,36 @@ class Tests_iOS: XCTestCase {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
func testDatesBetween() {
let today = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: Date())!
let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: today)!
let tenDaysAgo = Calendar.current.date(byAdding: .day, value: -10, to: today)!
let dates = Date.dates(from: Calendar.current.date(byAdding: .day, value: -10, to: Date())!, toDate: Date())
XCTAssertTrue(dates.last == yesterday)
XCTAssertTrue(dates.first == tenDaysAgo)
}
func testDatesIncluding() {
let today = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: Date())!
let yesterday = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: Date())!
let tenDaysAgo = Calendar.current.date(byAdding: .day, value: -10, to: today)!
func testLaunchPerformance() throws {
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
// This measures how long it takes to launch your application.
measure(metrics: [XCTApplicationLaunchMetric()]) {
XCUIApplication().launch()
}
}
let dates = Date.dates(from: Calendar.current.date(byAdding: .day, value: -10, to: Date())!, toDate: Date(), includingToDate: true)
XCTAssertTrue(dates.last == today)
XCTAssertTrue(dates.first == tenDaysAgo)
}
// func testLastVoteShouldExist() {
// let todayOneHourAhead = Calendar.current.date(byAdding: .day, value: 1, to: Date())!
// let fakeOnboarding = OnboardingData()
// fakeOnboarding.inputDay = DayOptions.Today
// fakeOnboarding.date = todayOneHourAhead
//
// let lastDay = ShowBasedOnVoteLogics.getLastDateVoteShouldExist(onboardingData: fakeOnboarding)
// let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
// XCTAssertTrue(lastDay == yesterday)
// }
}

View File

@@ -17,7 +17,7 @@ class Tests_iOSLaunchTests: XCTestCase {
continueAfterFailure = false
}
func testLaunch() throws {
func _testLaunch() throws {
let app = XCUIApplication()
app.launch()