From f74227f73837987069a506ea92f649e37f64d11a Mon Sep 17 00:00:00 2001 From: Marc Ole Bulling Date: Mon, 28 Dec 2020 15:30:35 +0100 Subject: [PATCH] Added Sqlite3 time to output --- grocy.openapi.json | 4 ++++ services/ApplicationService.php | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/grocy.openapi.json b/grocy.openapi.json index 784b4c90..5d786086 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -5215,6 +5215,10 @@ "type": "string", "format": "date-time" }, + "time_local_sqlite3": { + "type": "string", + "format": "date-time" + }, "time_utc": { "type": "string", "format": "date-time" diff --git a/services/ApplicationService.php b/services/ApplicationService.php index daab5081..1132a319 100644 --- a/services/ApplicationService.php +++ b/services/ApplicationService.php @@ -83,6 +83,13 @@ class ApplicationService extends BaseService return $dt->format('Y-m-d H:i:s'); } + + private static function getSqliteLocaltime(int $offset):string + { + $pdo = new \PDO('sqlite::memory:'); + return $pdo->query('SELECT datetime(\'now\', \'+' . $offset . ' seconds\', \'localtime\');')->fetch()[0]; + } + /** * Returns the response for the API call /system/time * @param int $offset an offset in seconds to be applied @@ -90,15 +97,16 @@ class ApplicationService extends BaseService */ public function GetSystemTime(int $offset = 0):array { - $timestamp = time()+$offset; + $timestamp = time() + $offset; $timeLocal = date('Y-m-d H:i:s', $timestamp); $timeUTC = self::convertToUtc($timestamp); return [ - 'timezone' => date_default_timezone_get(), - 'time_local' => $timeLocal, - 'time_utc' => $timeUTC, - 'timestamp' => $timestamp, - 'offset' => $offset + 'timezone' => date_default_timezone_get(), + 'time_local' => $timeLocal, + 'time_local_sqlite3' => self::getSqliteLocaltime($offset), + 'time_utc' => $timeUTC, + 'timestamp' => $timestamp, + 'offset' => $offset ]; } }