[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

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

   1  // $Id: date_timezone.js,v 1.1.4.2.2.1 2008/06/20 12:25:30 karens Exp $
   2  /**
   3   * Set the client's system time zone as default values of form fields.
   4   */
   5  Drupal.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(Drupal.settings.basePath, { 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  };


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7