From 691514b1022e74a913cdf64b44bd2379af679ae7 Mon Sep 17 00:00:00 2001 From: David Brazda Date: Tue, 27 Feb 2024 10:53:30 +0700 Subject: [PATCH] all dates in gui are in market time zone (even start/stop) --- v2realbot/static/index.html | 6 ++--- .../static/js/tables/archivetable/init.js | 18 +++++++------ v2realbot/static/js/tables/runmanager/init.js | 1 - v2realbot/static/js/utils/utils.js | 26 ++++++++++++++----- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/v2realbot/static/index.html b/v2realbot/static/index.html index b31df94..0c147ae 100644 --- a/v2realbot/static/index.html +++ b/v2realbot/static/index.html @@ -1150,7 +1150,7 @@ - + @@ -1160,13 +1160,13 @@ - + - + diff --git a/v2realbot/static/js/tables/archivetable/init.js b/v2realbot/static/js/tables/archivetable/init.js index 0351481..b5c5e17 100644 --- a/v2realbot/static/js/tables/archivetable/init.js +++ b/v2realbot/static/js/tables/archivetable/init.js @@ -70,30 +70,32 @@ function initialize_archiveRecords() { { targets: [5], render: function ( data, type, row ) { - now = new Date(data) if (type == "sort") { return new Date(data).getTime(); } + //data = "2024-02-26T19:29:13.400621-05:00" + // Create a date object from the string, represents given moment in time in UTC time var date = new Date(data); + tit = date.toLocaleString('cs-CZ', { timeZone: 'America/New_York', }) - if (isToday(now)) { + if (isToday(date)) { + console.log("volame isToday s", date) //return local time only - return '
'+ 'dnes ' + format_date(data,false,true)+'
' + return '
'+ 'dnes ' + format_date(data,true,true)+'
' } else { //return local datetime - return '
'+ format_date(data,false,false)+'
' + return '
'+ format_date(data,true,false)+'
' } }, }, { targets: [6], render: function ( data, type, row ) { - now = new Date(data) if (type == "sort") { return new Date(data).getTime(); } @@ -102,14 +104,14 @@ function initialize_archiveRecords() { timeZone: 'America/New_York', }) - if (isToday(now)) { + if (isToday(date)) { //return local time only - return '
'+ 'dnes ' + format_date(data,false,true)+'
' + return '
'+ 'dnes ' + format_date(data,true,true)+'
' } else { //return local datetime - return '
'+ format_date(data,false,false)+'
' + return '
'+ format_date(data,true,false)+'
' } }, }, diff --git a/v2realbot/static/js/tables/runmanager/init.js b/v2realbot/static/js/tables/runmanager/init.js index abd5e7b..2d8e358 100644 --- a/v2realbot/static/js/tables/runmanager/init.js +++ b/v2realbot/static/js/tables/runmanager/init.js @@ -168,7 +168,6 @@ function initialize_runmanagerRecords() { targets: [15,17, 18, 8, 9], //start, stop, valid_from, valid_to, bt_from, bt_to, last_proccessed render: function ( data, type, row ) { if (!data) return data - now = new Date(data) if (type == "sort") { return new Date(data).getTime(); } diff --git a/v2realbot/static/js/utils/utils.js b/v2realbot/static/js/utils/utils.js index f1d6243..5a85c50 100644 --- a/v2realbot/static/js/utils/utils.js +++ b/v2realbot/static/js/utils/utils.js @@ -990,12 +990,26 @@ JSON.safeStringify = (obj, indent = 2) => { return retVal; }; - function isToday(someDate) { - const today = new Date() - return someDate.getDate() == today.getDate() && - someDate.getMonth() == today.getMonth() && - someDate.getFullYear() == today.getFullYear() - } + +function isToday(someDate) { + // Convert input date to Eastern Time + var dateInEastern = new Date(someDate.toLocaleString('en-US', { timeZone: 'America/New_York' })); + console.log("vstupuje ",someDate) + console.log("americky ",dateInEastern) + // Get today's date in Eastern Time + var todayInEastern = new Date(new Date().toLocaleString('en-US', { timeZone: 'America/New_York' })); + + return dateInEastern.getDate() === todayInEastern.getDate() && + dateInEastern.getMonth() === todayInEastern.getMonth() && + dateInEastern.getFullYear() === todayInEastern.getFullYear(); +} +// function isToday(someDate) { + +// const today = new Date() +// return someDate.getDate() == today.getDate() && +// someDate.getMonth() == today.getMonth() && +// someDate.getFullYear() == today.getFullYear() +// } //https://www.w3schools.com/jsref/jsref_tolocalestring.asp function format_date(datum, markettime = false, timeonly = false) {