Uses external MongoDB, uses dates instead of strings for timestamps

This commit is contained in:
Patrick McDonagh
2017-02-13 12:23:03 -06:00
parent e2d5771a0c
commit fe60ba2292
3 changed files with 30 additions and 26 deletions

View File

@@ -2,7 +2,9 @@ package com.henrypump.poc;
import org.bson.Document;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import static java.lang.Math.abs;
@@ -44,7 +46,9 @@ public class Measurement {
Document lastStored = this.db.getLastStoredMeasurement(this.tagName);
try {
ZonedDateTime timestamp = ZonedDateTime.parse((CharSequence) lastStored.get("timestamp"));
Date lastStoredTimestamp = (Date) lastStored.get("timestamp");
ZonedDateTime timestamp = ZonedDateTime.ofInstant(lastStoredTimestamp.toInstant(),
ZoneId.systemDefault());
if (isToday(timestamp)){
this.average = lastStored.getDouble("dailyAverage");
this.total = lastStored.getDouble("dailyTotal");