Skip to content

Commit

Permalink
Update constants
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Jan 11, 2025
1 parent 0875917 commit 27c9660
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
12 changes: 12 additions & 0 deletions LifeSpace/SharedContext/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@

/// Constants shared across the application for settings
enum Constants {
// MARK: Survey Settings
/// Each day's survey opens by default in the evening at 7pm every day
/// and closes the next morning at 7am.
///
/// Hour to open the survey daily (in 24 hour time)
static let hourToOpenSurvey = 19
/// Hour to close the survey the following day (in 24 hour time)
static let hourToCloseSurvey = 7

// MARK: Location
/// Minimum distance between locations to record (in meters)
static let minDistanceBetweenPoints = 100.0

// MARK: URLs
/// URL of the privacy policy for the app
static let privacyPolicyURL = "https://michelleodden.com/cardinal-lifespace-privacy-policy/"

// MARK: Collections
/// User collection on Firestore
static let userCollectionName = "ls_users"
/// Location data collection on Firestore
Expand Down
4 changes: 2 additions & 2 deletions LifeSpace/Survey/DailySurveyTaskView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ struct DailySurveyTaskView: View {

response.surveyName = "dailySurveyTask"

/// If the user is taking the survey before 7am, the `surveyDate` should reflect the previous day,
/// If the user is taking the survey the morning after, the `surveyDate` should reflect the previous day,
/// otherwise it should reflect the current day.
let surveyDate: Date
if SurveyModule.currentHour < 7 {
if SurveyModule.currentHour < Constants.hourToCloseSurvey {
surveyDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())?.startOfDay ?? Date().startOfDay
} else {
surveyDate = Date().startOfDay
Expand Down
11 changes: 5 additions & 6 deletions LifeSpace/Survey/SurveyModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ enum SurveyModule {
}

static var isPreviousDaySurvey: Bool {
/// If the user is taking the survey before 7am, they should be informed that they are taking the
/// previous day's survey
currentHour < 7
/// If the user is taking the survey in the morning, they should be informed that their
/// results will apply to the previous day not the current day.
currentHour < Constants.hourToCloseSurvey
}

static var surveyAlreadyTaken: Bool {
let lastSurveyDateString = UserDefaults.standard.string(forKey: StorageKeys.lastSurveyDate)

/// Determine the survey date based on the current time
let surveyDate: Date
if currentHour < 7 {
if currentHour < Constants.hourToCloseSurvey {
surveyDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())?.startOfDay ?? Date().startOfDay
} else {
surveyDate = Date().startOfDay
Expand All @@ -44,7 +44,6 @@ enum SurveyModule {
}

static var shouldShowSurvey: Bool {
/// The survey should only be shown if it between 7pm and 7am
currentHour < 7 || currentHour >= 19
currentHour < Constants.hourToCloseSurvey || currentHour >= Constants.hourToOpenSurvey
}
}

0 comments on commit 27c9660

Please sign in to comment.