From 81df6a36b4b77fcf3f76658d7359fae0d541cf61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sun, 30 Nov 2014 19:43:34 -0500 Subject: [PATCH] Add getTimezone() procedure to the API --- docs/api-json-rpc.markdown | 27 +++++++++++++++++++++++++++ jsonrpc.php | 7 +++++++ tests/functionals/ApiTest.php | 7 +++++++ 3 files changed, 41 insertions(+) diff --git a/docs/api-json-rpc.markdown b/docs/api-json-rpc.markdown index d30ac362f..5280600e9 100644 --- a/docs/api-json-rpc.markdown +++ b/docs/api-json-rpc.markdown @@ -144,6 +144,33 @@ Array Procedures ---------- +### getTimezone + +- Purpose: **Get the application timezone** +- Parameters: none +- Result on success: **Timezone** (Example: UTC, Europe/Paris) +- Result on failure: **Default timezone** (UTC) + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "getTimezone", + "id": 1661138292 +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 1661138292, + "result": "Europe\/Paris" +} +``` + ### createProject - Purpose: **Create a new project** diff --git a/jsonrpc.php b/jsonrpc.php index e9a50b35f..75a55c927 100644 --- a/jsonrpc.php +++ b/jsonrpc.php @@ -337,6 +337,13 @@ $server->register('updateSubtask', function($id, $task_id, $title = null, $user_ return $valid && $subTaskModel->update($values); }); +/** + * Application procedures + */ +$server->register('getTimezone', function() use($configModel) { + return $configModel->get('application_timezone'); +}); + /** * Parse incoming requests */ diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php index ece7b46d0..a8f8869bc 100644 --- a/tests/functionals/ApiTest.php +++ b/tests/functionals/ApiTest.php @@ -29,6 +29,7 @@ class Api extends PHPUnit_Framework_TestCase $service->getInstance(); $pdo->exec("UPDATE settings SET value='".API_KEY."' WHERE option='api_token'"); + $pdo->exec("UPDATE settings SET value='Europe/Paris' WHERE option='application_timezone'"); $pdo = null; } @@ -48,6 +49,12 @@ class Api extends PHPUnit_Framework_TestCase return $tasks[0]['id']; } + public function testGetTimezone() + { + $timezone = $this->client->getTimezone(); + $this->assertEquals('Europe/Paris', $timezone); + } + public function testRemoveAll() { $projects = $this->client->getAllProjects();