Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
marionbarker committed Dec 20, 2023
2 parents 189ffae + a16f79b commit 4af380d
Showing 6 changed files with 20 additions and 36 deletions.
2 changes: 1 addition & 1 deletion LoopFollow/Controllers/Nightscout/CAge.swift
Original file line number Diff line number Diff line change
@@ -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,
4 changes: 2 additions & 2 deletions LoopFollow/Controllers/Nightscout/SAge.swift
Original file line number Diff line number Diff line change
@@ -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,
5 changes: 2 additions & 3 deletions LoopFollow/Controllers/Nightscout/Treatments.swift
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions LoopFollow/ViewControllers/SettingsViewController.swift
Original file line number Diff line number Diff line change
@@ -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 = ""
42 changes: 13 additions & 29 deletions LoopFollow/helpers/DateTime.swift
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 4af380d

Please sign in to comment.