[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/date/date_timezone/ -> date_timezone.js (source)

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


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7