mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 20:36:15 +02:00
Inital structure for /system/time API call
This commit is contained in:
parent
6fcc0636e8
commit
669d2d1e48
|
|
@ -43,6 +43,11 @@ class SystemApiController extends BaseApiController
|
|||
return $this->ApiResponse($response, $this->getApplicationService()->GetSystemInfo());
|
||||
}
|
||||
|
||||
public function GetSystemTime(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
return $this->ApiResponse($response, $this->getApplicationService()->GetSystemTime());
|
||||
}
|
||||
|
||||
public function LogMissingLocalization(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
if (GROCY_MODE === 'dev')
|
||||
|
|
|
|||
|
|
@ -145,6 +145,7 @@ $app->group('/api', function (RouteCollectorProxy $group) {
|
|||
|
||||
// System
|
||||
$group->get('/system/info', '\Grocy\Controllers\SystemApiController:GetSystemInfo');
|
||||
$group->get('/system/time', '\Grocy\Controllers\SystemApiController:GetSystemTime');
|
||||
$group->get('/system/db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime');
|
||||
$group->get('/system/config', '\Grocy\Controllers\SystemApiController:GetConfig');
|
||||
$group->post('/system/log-missing-localization', '\Grocy\Controllers\SystemApiController:LogMissingLocalization');
|
||||
|
|
|
|||
|
|
@ -75,4 +75,31 @@ class ApplicationService extends BaseService
|
|||
'sqlite_version' => $sqliteVersion
|
||||
];
|
||||
}
|
||||
|
||||
private static function convertToUtc(int $timestamp):string
|
||||
{
|
||||
$timestamp = time();
|
||||
$dt = new DateTime('now', new DateTimeZone('UTC'));
|
||||
$dt->setTimestamp($timestamp);
|
||||
return $dt->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the response for the API call /system/time
|
||||
* @param int $offset an offset to be applied
|
||||
* @return array
|
||||
*/
|
||||
public function GetSystemTime(int $offset = 0):array
|
||||
{
|
||||
$timestamp = time();
|
||||
$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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user