diff --git a/LoopFollow/Controllers/Nightscout/CAge.swift b/LoopFollow/Controllers/Nightscout/CAge.swift index c51f77e9..c56abf03 100644 --- a/LoopFollow/Controllers/Nightscout/CAge.swift +++ b/LoopFollow/Controllers/Nightscout/CAge.swift @@ -10,7 +10,7 @@ import Foundation extension MainViewController { // NS Cage Web Call func webLoadNSCage() { - let currentTimeString = dateTimeUtils.getCurrentDateTimeString() + let currentTimeString = dateTimeUtils.getDateTimeString() let parameters: [String: String] = [ "find[eventType]": NightscoutUtils.EventType.cage.rawValue, diff --git a/LoopFollow/Controllers/Nightscout/SAge.swift b/LoopFollow/Controllers/Nightscout/SAge.swift index fc014184..eb7743e2 100644 --- a/LoopFollow/Controllers/Nightscout/SAge.swift +++ b/LoopFollow/Controllers/Nightscout/SAge.swift @@ -10,8 +10,8 @@ import Foundation extension MainViewController { // NS Sage Web Call func webLoadNSSage() { - let lastDateString = dateTimeUtils.nowMinus60DaysTimeInterval() - let currentTimeString = dateTimeUtils.getCurrentDateTimeString() + let lastDateString = dateTimeUtils.getDateTimeString(addingDays: -60) + let currentTimeString = dateTimeUtils.getDateTimeString() let parameters: [String: String] = [ "find[eventType]": NightscoutUtils.EventType.sage.rawValue, diff --git a/LoopFollow/Controllers/Nightscout/Treatments.swift b/LoopFollow/Controllers/Nightscout/Treatments.swift index 03f874e3..4305d8f6 100644 --- a/LoopFollow/Controllers/Nightscout/Treatments.swift +++ b/LoopFollow/Controllers/Nightscout/Treatments.swift @@ -14,9 +14,8 @@ extension MainViewController { if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Download: Treatments") } if !UserDefaultsRepository.downloadTreatments.value { return } - let graphHours = 24 * UserDefaultsRepository.downloadDays.value - let startTimeString = dateTimeUtils.nowMinusNHoursTimeInterval(N: graphHours) - let currentTimeString = dateTimeUtils.getCurrentDateTimeString() + let startTimeString = dateTimeUtils.getDateTimeString(addingDays: -1 * UserDefaultsRepository.downloadDays.value) + let currentTimeString = dateTimeUtils.getDateTimeString(addingHours: 6) let parameters: [String: String] = [ "find[created_at][$gte]": startTimeString, "find[created_at][$lte]": currentTimeString diff --git a/LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift b/LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift index 36217f10..8f276ba6 100644 --- a/LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift +++ b/LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift @@ -43,7 +43,7 @@ extension MainViewController { offset = bolusTime.offset ? 70 : 20 } - if dateTimeStamp < (dateTimeUtils.getNowTimeIntervalUTC() + (60 * 60)) { + if dateTimeStamp < (dateTimeUtils.getNowTimeIntervalUTC() + (3600 * UserDefaultsRepository.predictionToLoad.value)) { // Make the dot let dot = carbGraphStruct(value: Double(carbs), date: Double(dateTimeStamp), sgv: Int(sgv.sgv + Double(offset)), absorptionTime: absorptionTime) carbData.append(dot) diff --git a/LoopFollow/ViewControllers/SettingsViewController.swift b/LoopFollow/ViewControllers/SettingsViewController.swift index 78968f72..74eef9e5 100644 --- a/LoopFollow/ViewControllers/SettingsViewController.swift +++ b/LoopFollow/ViewControllers/SettingsViewController.swift @@ -106,6 +106,7 @@ class SettingsViewController: FormViewController { }.cellSetup { (cell, row) in cell.textField.autocorrectionType = .no cell.textField.autocapitalizationType = .none + cell.textField.textContentType = .password }.onChange { row in if row.value == nil { UserDefaultsRepository.token.value = "" diff --git a/LoopFollow/helpers/DateTime.swift b/LoopFollow/helpers/DateTime.swift index 03f3030a..1b8f7cca 100644 --- a/LoopFollow/helpers/DateTime.swift +++ b/LoopFollow/helpers/DateTime.swift @@ -57,42 +57,26 @@ class dateTimeUtils { return utcTime } - static func getCurrentDateTimeString() -> String { - let currentTimeInterval = getNowTimeIntervalUTC() + static func getDateTimeString(addingHours hours: Int? = nil, addingDays days: Int? = nil) -> String { + let currentDate = Date() + var date = currentDate - let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss" - dateFormatter.locale = Locale(identifier: "en_US") - dateFormatter.timeZone = TimeZone.init(secondsFromGMT: 0) + if let hoursToAdd = hours { + date = Calendar.current.date(byAdding: .hour, value: hoursToAdd, to: currentDate)! + } - let currentDate = Date(timeIntervalSince1970: currentTimeInterval) - let currentTimeString = dateFormatter.string(from: currentDate) + if let daysToAdd = days { + date = Calendar.current.date(byAdding: .day, value: daysToAdd, to: currentDate)! + } - return currentTimeString - } - - static func nowMinusNHoursTimeInterval(N: Int) -> String { - let today = Date() - let nHoursAgo = Calendar.current.date(byAdding: .hour, value: -N, to: today)! let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss" dateFormatter.locale = Locale(identifier: "en_US") - dateFormatter.timeZone = TimeZone.init(secondsFromGMT: 0) - let nHoursAgoString = dateFormatter.string(from: nHoursAgo) - return nHoursAgoString - } - - static func nowMinus60DaysTimeInterval() -> String { - let today = Date() - let oldDate = Calendar.current.date(byAdding: .day, value: -10, to: today)! - let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd" - dateFormatter.locale = Locale(identifier: "en_US") - dateFormatter.timeZone = TimeZone.init(secondsFromGMT: 0) - let dayString = dateFormatter.string(from: oldDate) - return dayString + dateFormatter.timeZone = TimeZone(secondsFromGMT: 0) + + return dateFormatter.string(from: date) } - + static func printNow() -> String { let date = Date() let formatter = DateFormatter()