From 410ea26b0ef41eacbeeba8033cc9be575e7b3bae Mon Sep 17 00:00:00 2001 From: bergware Date: Fri, 27 Oct 2023 12:40:38 +0200 Subject: [PATCH] Dashboard: display date and time in user selected formats --- emhttp/plugins/dynamix/nchan/update_3 | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/emhttp/plugins/dynamix/nchan/update_3 b/emhttp/plugins/dynamix/nchan/update_3 index a9ba9ad19..024ee30ce 100755 --- a/emhttp/plugins/dynamix/nchan/update_3 +++ b/emhttp/plugins/dynamix/nchan/update_3 @@ -58,9 +58,15 @@ function port_get_contents($port) { } function esc($text) { + // escape literal text in date format string return "\\".join("\\",str_split($text)); } +function mix($text) { + // convert linux date format to PHP equivalent + return str_replace(['%A','%Y','%B','%e','%m','%d'],['l','Y','F','j','m','d'],$text); +} + // initialize variables $time0 = $time = microtime(true); foreach (ports() as $port) { @@ -124,15 +130,10 @@ while (true) { } // current date and time $now = time(); - if (_var($display,'time')=='%R') { - // 24 hour format - $clock = date('G:i',$now); - } else { - // 12 hour format wih am/pm - $clock = date('g:i '.esc('').'a'.esc(''),$now); - } - $timedate = "$clock\n"._(date('l, F j, Y, '.esc(_('UTC')).'P',$now),0).(date('I',$now) ? ' '._('DST').'' : ''); - publish('update3',implode("\n",$echo)."\1".implode("\0",$mode)."\1".implode("\0",$rxtx)."\1".implode("\0",$stat)."\1".$timedate); + $clock = _var($display,'time')=='%R' ? date('G:i',$now) : date('g:i '.esc('').'a'.esc(''),$now); + $date = _var($display,'date','%c')=='%c' ? date('l, F j, Y, '.esc(_('UTC')).'P',$now) : date(mix($display['date']).', '.esc(_('UTC')).'P',$now); + $dst = date('I',$now) ? ' '._('DST').'' : ''; + publish('update3',implode("\n",$echo)."\1".implode("\0",$mode)."\1".implode("\0",$rxtx)."\1".implode("\0",$stat)."\1"."$clock\n"._($date,0).$dst); $time0 = $time; sleep(1); $time = microtime(true);