use server time
This commit is contained in:
parent
b2e445478c
commit
887298a5bd
3 changed files with 21 additions and 16 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue