annotate core/modules/system/src/Controller/TimezoneController.php @ 19:fa3358dc1485 tip

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