Chris@0: /** Chris@0: * DO NOT EDIT THIS FILE. Chris@0: * See the following change record for more information, Chris@0: * https://www.drupal.org/node/2815083 Chris@0: * @preserve Chris@0: **/ Chris@0: Chris@0: (function ($, Drupal) { Chris@0: Drupal.behaviors.setTimezone = { Chris@0: attach: function attach(context, settings) { Chris@0: var $timezone = $(context).find('.timezone-detect').once('timezone'); Chris@0: if ($timezone.length) { Chris@0: var dateString = Date(); Chris@0: Chris@0: var matches = dateString.match(/\(([A-Z]{3,5})\)/); Chris@0: var abbreviation = matches ? matches[1] : 0; Chris@0: Chris@0: var dateNow = new Date(); Chris@0: var offsetNow = dateNow.getTimezoneOffset() * -60; Chris@0: Chris@0: var dateJan = new Date(dateNow.getFullYear(), 0, 1, 12, 0, 0, 0); Chris@0: var dateJul = new Date(dateNow.getFullYear(), 6, 1, 12, 0, 0, 0); Chris@0: var offsetJan = dateJan.getTimezoneOffset() * -60; Chris@0: var offsetJul = dateJul.getTimezoneOffset() * -60; Chris@0: Chris@0: var isDaylightSavingTime = void 0; Chris@0: Chris@0: if (offsetJan === offsetJul) { Chris@0: isDaylightSavingTime = ''; Chris@0: } else if (Math.max(offsetJan, offsetJul) === offsetNow) { Chris@0: isDaylightSavingTime = 1; Chris@0: } else { Chris@0: isDaylightSavingTime = 0; Chris@0: } Chris@0: Chris@0: var path = 'system/timezone/' + abbreviation + '/' + offsetNow + '/' + isDaylightSavingTime; Chris@0: $.ajax({ Chris@0: async: false, Chris@0: url: Drupal.url(path), Chris@0: data: { date: dateString }, Chris@0: dataType: 'json', Chris@0: success: function success(data) { Chris@0: if (data) { Chris@0: $timezone.val(data); Chris@0: } Chris@0: } Chris@0: }); Chris@0: } Chris@0: } Chris@0: }; Chris@0: })(jQuery, Drupal);