From 28f23510e217f23f105944077b1b5705b459f52f Mon Sep 17 00:00:00 2001 From: vitor-costa Date: Sat, 6 Dec 2014 20:25:46 -0200 Subject: [PATCH] Storages an empty json in file if it is outdated by more than one hour. --- dataQueuer.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dataQueuer.js b/dataQueuer.js index 6d00fe7..8e6f7b8 100644 --- a/dataQueuer.js +++ b/dataQueuer.js @@ -71,6 +71,17 @@ function data_formatter() { return formatted_data; } +function getDateTimeBoundary(hour) { + var now = new Date(); + var offset = hour * 60 * 60 * 1000; + + return new Date(now.getTime() - offset); +} + +function toDateTime(dateTimeString) { + return new Date(dateTimeString); +} + // Grabs data from riob.us/all and enqueues it in the json file in time intervals setInterval(function() { // Make GET Request @@ -79,6 +90,9 @@ setInterval(function() { // Checks if data already has been generated by JSON.parse. if(data != null) { // var formatted_data = data_formatter(); + if(toDateTime(data.LASTUPDATE) < getDateTimeBoundary(1)) { + data = JSON.parse("{}"); + } appendDataAsync(JSON.stringify(data)); } }, intervalTime); \ No newline at end of file