diff --git a/app.py b/app.py index dcea74f..e951ce8 100755 --- a/app.py +++ b/app.py @@ -191,4 +191,5 @@ def get_data_route(): outdoor_data = get_outdoor_data_current() merged_data = merge_data(indoor_data, outdoor_data) merged_data["location"] = location + merged_data["server_time"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) return jsonify(merged_data) \ No newline at end of file diff --git a/static/card.html b/static/card.html index 1a261d8..dbf7beb 100644 --- a/static/card.html +++ b/static/card.html @@ -223,11 +223,10 @@ return "#" + (0x1000000 + (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 + (G < 255 ? G < 1 ? 0 : G : 255) * 0x100 + (B < 255 ? B < 1 ? 0 : B : 255)).toString(16).slice(1); } - function dateIsToday(date) { - var today = new Date(); - return date.getDate() == today.getDate() && - date.getMonth() == today.getMonth() && - date.getFullYear() == today.getFullYear(); + function dateIsToday(date, server_date) { + return date.getDate() == server_date.getDate() && + date.getMonth() == server_date.getMonth() && + date.getFullYear() == server_date.getFullYear(); } // Fetch data from API @@ -256,14 +255,17 @@ // The location is the location key in the JSON response // It must also be appended with the timestamp var update_time = data.time_outdoor + var server_time = data.server_time // First we parse the date string into a Date object // Data is in format YYYY-MM-DD hh:mm:ss var update_date = new Date(update_time); - console.log (update_date); - console.log(dateIsToday(update_date)) + // Then we get the server's current date + var server_date = new Date(server_time) + console.log (server_date); + console.log(dateIsToday(update_date,server_date)) // If the update time is not today, we will show the date and time // Otherwise, we will show the time - if (dateIsToday(update_date)) { + if (dateIsToday(update_date,server_date)) { // We only want hh:mm when the update time is today update_time = update_time.substring(11, 16); $("#title").text(data.location + " @ " + update_time); diff --git a/static/square.html b/static/square.html index 7f61a45..b4202ce 100644 --- a/static/square.html +++ b/static/square.html @@ -127,11 +127,10 @@