PageSourceSearch

http://www.lluisribas.net/sites/all/modules/date/date_timezone/date_timezone.js

js lluisribas.net collected 2026-10-02 13:42:22 UTC 1,996 bytes, 48 lines download raw bytes

1// $Id: date_timezone.js,v 1.1.2.3 2008/06/20 12:26:06 karens Exp $
2/**
3 * Set the client's system time zone as default values of form fields.
4 */
5Drupal.setDefaultTimezone = function() {
6  var dateString = Date();
7  // In some client environments, date strings include a time zone 
8  // abbreviation which can be interpreted by PHP.
9  var matches = Date().match(/\(([A-Z]{3,5})\)/);
10  var abbreviation = matches ? matches[1] : 0;
11
12  // For all other client environments, the abbreviation is set to "0" 
13  // and the current offset from UTC and daylight saving time status are 
14  // used to guess the time zone.
15  var dateNow = new Date();
16  var offsetNow = dateNow.getTimezoneOffset() * -60;
17
18  // Use January 1 and July 1 as test dates for determining daylight 
19  // saving time status by comparing their offsets.
20  var dateJan = new Date(dateNow.getFullYear(), 0, 1, 12, 0, 0, 0);
21  var dateJul = new Date(dateNow.getFullYear(), 6, 1, 12, 0, 0, 0);
22  var offsetJan = dateJan.getTimezoneOffset() * -60;
23  var offsetJul = dateJul.getTimezoneOffset() * -60;
24
25  // If the offset from UTC is identical on January 1 and July 1, 
26  // assume daylight saving time is not used in this time zone.
27  if (offsetJan == offsetJul) {
28    var isDaylightSavingTime = '';
29  }
30  // If the maximum annual offset is equivalent to the current offset, 
31  // assume daylight saving time is in effect.
32  else if (Math.max(offsetJan, offsetJul) == offsetNow) {
33    var isDaylightSavingTime = 1;
34  }
35  // Otherwise, assume daylight saving time is not in effect.
36  else {
37    var isDaylightSavingTime = 0;
38  }
39
40  // Submit request to the user/timezone callback and set the form field 
41  // to the response time zone.
42  var path = 'user/timezone/' + abbreviation + '/' + offsetNow + '/' + isDaylightSavingTime;
43  $.getJSON(location.pathname, { q: path, date: dateString }, function (data) {
44    if (data) {
45      $("#edit-date-default-timezone, #edit-user-register-timezone, #edit-timezone-name").val(data);
46    }
47  });
48};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.