use server time
This commit is contained in:
parent
b2e445478c
commit
887298a5bd
1
app.py
1
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)
|
|
@ -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);
|
||||
|
|
|
@ -127,11 +127,10 @@
|
|||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
|
@ -161,12 +160,15 @@
|
|||
// 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
|
||||
// Parse the string to Date object
|
||||
update_time = new Date(update_time);
|
||||
var update_date = new Date(update_time);
|
||||
// Then we get the server's current date
|
||||
var server_date = new Date(server_time)
|
||||
|
||||
// If the date not today, we want to show show the offline icon
|
||||
if (!dateIsToday(update_time)) {
|
||||
if (!dateIsToday(update_date, server_date)) {
|
||||
$("#offline_icon").css("display", "block");
|
||||
} else {
|
||||
$("#offline_icon").css("display", "none");
|
||||
|
|
Loading…
Reference in New Issue