瀏覽代碼

Cleanup on the chart syncing and end of the basal graph

Jon Fawcett 6 年之前
父節點
當前提交
28ad8b78ec
共有 3 個文件被更改,包括 16 次插入11 次删除
  1. 3 4
      LoopFollow/Controllers/Graphs.swift
  2. 4 4
      LoopFollow/Controllers/NightScout.swift
  3. 9 3
      LoopFollow/helpers/DateTime.swift

+ 3 - 4
LoopFollow/Controllers/Graphs.swift

@@ -134,8 +134,8 @@ extension MainViewController {
             BGChart.zoom(scaleX: 18, scaleY: 1, x: 1, y: 1)
             firstGraphLoad = false
         }
-        // 7000 only shows 30 minutes of the hour predictions, leaving the rest on the right of the screen requiring a scroll
-        BGChart.moveViewToX(Date().timeIntervalSince1970)
+        BGChart.moveViewToX(dateTimeUtils.getNowTimeIntervalUTC() - (BGChart.visibleXRange * 0.7))
+        
 
         
         createSmallBGGraph(bgChartEntry: bgChartEntry, colors: colors)
@@ -204,8 +204,7 @@ extension MainViewController {
             BasalChart.zoom(scaleX: 18, scaleY: 1, x: 1, y: 1)
             firstBasalGraphLoad = false
         }
-        // 7000 only shows 30 minutes of the hour predictions, leaving the rest on the right of the screen requiring a scroll
-        BasalChart.moveViewToX(Date().timeIntervalSince1970)
+        BasalChart.moveViewToX(dateTimeUtils.getNowTimeIntervalUTC() - (BGChart.visibleXRange * 0.7))
         
         // Bar Chart Build
         /*var chartEntry = [BarChartDataEntry]()

+ 4 - 4
LoopFollow/Controllers/NightScout.swift

@@ -649,9 +649,9 @@ extension MainViewController {
               basalData.append(startDot)
             
             // Make the ending dot
-            // If it's the last one and not ended yet, extend it for 1 hour to matc the prediction length. Otherwise let it end
-            if i == entries.count - 1 && dateTimeStamp + duration <= Date().timeIntervalSince1970 {
-                lastEndDot = Date().timeIntervalSince1970 + (60 * 60)
+            // If it's the last one and not ended yet, extend it for 1 hour to match the prediction length. Otherwise let it end
+            if i == entries.count - 1 && dateTimeStamp + duration <= dateTimeUtils.getNowTimeIntervalUTC() {
+                lastEndDot = Date().timeIntervalSince1970 + (55 * 60)
             } else {
                 lastEndDot = dateTimeStamp + (duration * 60)
             }
@@ -662,7 +662,7 @@ extension MainViewController {
           }
         
         // If last scheduled basal was prior to right now, we need to create one last scheduled entry
-        if lastEndDot <= Date().timeIntervalSince1970 {
+        if lastEndDot <= dateTimeUtils.getNowTimeIntervalUTC() {
             var scheduled = 0.0
                 // cycle through basal profiles.
                 // TODO figure out how to deal with profile changes that happen mid-gap

+ 9 - 3
LoopFollow/helpers/DateTime.swift

@@ -37,9 +37,15 @@ class dateTimeUtils {
         return midnightTimeInterval
     }
     
-    static func getNowTimeInterval() -> TimeInterval {
-        let now = Date().timeIntervalSince1970
-        return now
+    static func getNowTimeIntervalUTC() -> TimeInterval {
+        let now = Date()
+        let formatter = DateFormatter()
+        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
+        formatter.timeZone = TimeZone(abbreviation: "UTC")
+        let utc = formatter.string(from: now)
+        let day = formatter.date(from: utc)
+        guard let utcTime = day?.timeIntervalSince1970 else { return 0 }
+        return utcTime
     }
     
 }