dg9vh / MMDVMHost-Dashboard

Dashboard for MMDVMHost (by G4KLX)
Creative Commons Zero v1.0 Universal
60 stars 45 forks source link

Uncaught Exception: DateTime::__construct(): The timezone could not be found in the database #174

Closed m1geo closed 6 years ago

m1geo commented 6 years ago

Hi folks. Issue in the latest commit. Cannot pass timezone. My timezone is BST:

m1geo@repeater:/var/log/$ date +"%Z %z" BST +0100 m1geo@repeater:/var/log/$ date Sun 1 Apr 23:18:35 BST 2018

The exact error in the CGI log is:

2018-04-01 22:31:56: (mod_fastcgi.c.2695) FastCGI-stderr: thrown in /opt/MMDVMHost-Dashboard/include/tools.php on line 116 2018-04-01 22:49:27: (mod_fastcgi.c.2695) FastCGI-stderr: PHP Fatal error: Uncaught Exception: DateTime::construct(): Failed to parse time string (ary file /opt/MMDVMHost) at position 0 (a): The timezone could not be found in the database in /opt/MMDVMHost-Dashboard/include/tools.php:116 2018-04-01 22:49:27: (mod_fastcgi.c.2695) FastCGI-stderr: Stack trace: 2018-04-01 22:49:27: (mod_fastcgi.c.2695) FastCGI-stderr: #0 /opt/MMDVMHost-Dashboard/include/tools.php(116): DateTime->construct('ary file /opt/M...') 2018-04-01 22:49:27: (mod_fastcgi.c.2695) FastCGI-stderr: #1 /opt/MMDVMHost-Dashboard/include/functions.php(524): convertTimezone('ary file /opt/M...') 2018-04-01 22:49:27: (mod_fastcgi.c.2695) FastCGI-stderr: #2 /opt/MMDVMHost-Dashboard/include/functions.php(545): getHeardList(Array, false) 2018-04-01 22:49:27: (mod_fastcgi.c.2695) FastCGI-stderr: #3 /opt/MMDVMHost-Dashboard/include/init.php(13): getLastHeard(Array, false) 2018-04-01 22:49:27: (mod_fastcgi.c.2695) FastCGI-stderr: #4 /opt/MMDVMHost-Dashboard/index.php(25): include('/opt/MMDVMHost-...') 2018-04-01 22:49:27: (mod_fastcgi.c.2695) FastCGI-stderr: #5 {main} 2018-04-01 22:49:27: (mod_fastcgi.c.2695) FastCGI-stderr: thrown in /opt/MMDVMHost-Dashboard/include/tools.php on line 116

I guess this is following updates from the OS and the recently changed timezone (UTC to BST).

Thanks, George M1GEO.

m1geo commented 6 years ago

I had a quick poke around. Added a simple string printer to the convertTimezone(...): echo("String: " . $timestamp . "<br>\n");

The following output shows the issue:

String: 2018-04-01 04:09:04.978 String: 2018-04-01 04:08:22.983 String: 2018-04-01 04:08:09.183 String: 2018-04-01 04:07:42.321 String: 2018-04-01 04:07:41.115 String: ary file /opt/MMDVMHost [crash]

Clearly it cannot parse: "ary file /opt/MMDVMHost"

Not sure why this happens, or why it's trying to parse such a string?

George M1GEO

m1geo commented 6 years ago

I fixed (think hacked!) it with a try and catch block:

function convertTimezone($timestamp) { try { $date = new DateTime($timestamp); $date->setTimezone(new DateTimeZone(TIMEZONE)); return $date->format('Y-m-d H:i:s'); } catch (Exception $err) { //echo 'Error: ' . $err->getMessage(); } }

dg9vh commented 6 years ago

If this is the way it works, please make a pull request. Tnx-- Amateurfunk ist das, was uns verbindet! Bleiben wir in Kontakt! Ortsverband Q05, VölklingenAm 02.04.2018 02:05 schrieb George Smart notifications@github.com:I fixed (think hacked!) it with a try and catch block:

function convertTimezone($timestamp) { try { $date = new DateTime($timestamp); $date->setTimezone(new DateTimeZone(TIMEZONE)); return $date->format('Y-m-d H:i:s'); } catch (Exception $err) { //echo 'Error: ' . $err->getMessage(); } }

—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.