Mercurial > hg > isophonics-drupal-site
comparison core/modules/system/src/Controller/TimezoneController.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\system\Controller; | |
4 | |
5 use Symfony\Component\HttpFoundation\JsonResponse; | |
6 | |
7 /** | |
8 * Provides a callback for finding out a timezone name. | |
9 */ | |
10 class TimezoneController { | |
11 | |
12 /** | |
13 * Retrieve a JSON object containing a time zone name given a timezone | |
14 * abbreviation. | |
15 * | |
16 * @param string $abbreviation | |
17 * Time zone abbreviation. | |
18 * @param int $offset | |
19 * Offset from GMT in seconds. Defaults to -1 which means that first found | |
20 * time zone corresponding to abbr is returned. Otherwise exact offset is | |
21 * searched and only if not found then the first time zone with any offset | |
22 * is returned. | |
23 * @param null|bool $is_daylight_saving_time | |
24 * Daylight saving time indicator. If abbr does not exist then the time | |
25 * zone is searched solely by offset and isdst. | |
26 * | |
27 * @return JsonResponse | |
28 * The timezone name in JsonResponse object. | |
29 */ | |
30 public function getTimezone($abbreviation = '', $offset = -1, $is_daylight_saving_time = NULL) { | |
31 // An abbreviation of "0" passed in the callback arguments should be | |
32 // interpreted as the empty string. | |
33 $abbreviation = $abbreviation ? $abbreviation : ''; | |
34 $timezone = timezone_name_from_abbr($abbreviation, intval($offset), $is_daylight_saving_time); | |
35 return new JsonResponse($timezone); | |
36 } | |
37 | |
38 } |