mirror of
https://github.com/grocy/grocy.git
synced 2026-04-10 14:36:16 +02:00
Review
This commit is contained in:
parent
f602719794
commit
16f400447a
|
|
@ -44,13 +44,28 @@ class SystemApiController extends BaseApiController
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetSystemTime(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
public function GetSystemTime(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
$params = $request->getQueryParams();
|
$params = $request->getQueryParams();
|
||||||
if (isset($params['offset']))
|
if (isset($params['offset']))
|
||||||
|
{
|
||||||
|
if (!filter_var($params['offset'], FILTER_VALIDATE_INT))
|
||||||
|
{
|
||||||
|
throw new \Exception('Query parameter "offset" is not a valid integer');
|
||||||
|
}
|
||||||
|
|
||||||
$offset = $params['offset'];
|
$offset = $params['offset'];
|
||||||
|
}
|
||||||
|
|
||||||
return $this->ApiResponse($response, $this->getApplicationService()->GetSystemTime($offset));
|
return $this->ApiResponse($response, $this->getApplicationService()->GetSystemTime($offset));
|
||||||
}
|
}
|
||||||
|
catch (\Exception $ex)
|
||||||
|
{
|
||||||
|
return $this->GenericErrorResponse($response, $ex->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function LogMissingLocalization(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
public function LogMissingLocalization(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -76,29 +76,32 @@ class ApplicationService extends BaseService
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function convertToUtc(int $timestamp):string
|
private static function convertToUtc(int $timestamp): string
|
||||||
{
|
{
|
||||||
$dt = new \DateTime('now', new \DateTimeZone('UTC'));
|
$dt = new \DateTime('now', new \DateTimeZone('UTC'));
|
||||||
$dt->setTimestamp($timestamp);
|
$dt->setTimestamp($timestamp);
|
||||||
return $dt->format('Y-m-d H:i:s');
|
return $dt->format('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function getSqliteLocaltime(int $offset): string
|
||||||
private static function getSqliteLocaltime(int $offset):string
|
|
||||||
{
|
{
|
||||||
$pdo = new \PDO('sqlite::memory:');
|
$pdo = new \PDO('sqlite::memory:');
|
||||||
if ($offset > 0)
|
if ($offset > 0)
|
||||||
|
{
|
||||||
return $pdo->query('SELECT datetime(\'now\', \'+' . $offset . ' seconds\', \'localtime\');')->fetch()[0];
|
return $pdo->query('SELECT datetime(\'now\', \'+' . $offset . ' seconds\', \'localtime\');')->fetch()[0];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return $pdo->query('SELECT datetime(\'now\', \'' . $offset . ' seconds\', \'localtime\');')->fetch()[0];
|
return $pdo->query('SELECT datetime(\'now\', \'' . $offset . ' seconds\', \'localtime\');')->fetch()[0];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the response for the API call /system/time
|
* Returns the response for the API call /system/time
|
||||||
* @param int $offset an offset in seconds to be applied
|
* @param int $offset an offset in seconds to be applied
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function GetSystemTime(int $offset = 0):array
|
public function GetSystemTime(int $offset = 0): array
|
||||||
{
|
{
|
||||||
$timestamp = time() + $offset;
|
$timestamp = time() + $offset;
|
||||||
$timeLocal = date('Y-m-d H:i:s', $timestamp);
|
$timeLocal = date('Y-m-d H:i:s', $timestamp);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user