3 namespace Drupal\system\Controller;
5 use Symfony\Component\HttpFoundation\JsonResponse;
8 * Provides a callback for finding out a timezone name.
10 class TimezoneController {
13 * Retrieve a JSON object containing a time zone name given a timezone
16 * @param string $abbreviation
17 * Time zone abbreviation.
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
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.
27 * @return \Symfony\Component\HttpFoundation\JsonResponse
28 * The timezone name in JsonResponse object.
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);