? LICENSE.txt
? clock
? clock.make
Index: clock.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/clock/clock.js,v
retrieving revision 1.9
diff -d -u -p -r1.9 clock.js
--- clock.js	2 Feb 2010 02:05:36 -0000	1.9
+++ clock.js	21 Mar 2010 19:54:45 -0000
@@ -6,18 +6,20 @@
  * date is recalculated every second to make the clock dynamic.
  */
 Drupal.behaviors.clockDisplay = function (context) {
-  // Gets a PHP timestamp, which counts the seconds since the begin of the UNIX-era.
-  var clockTimestampString = Drupal.settings['0'];
-  // The time zone offset in seconds.
-  var clockTimezoneOffsetSeconds = Drupal.settings['1'];
+  // Whether or not to update the clock continuously
+  var clockUpdate = Drupal.settings['0'];
+  // Gets a PHP timestamp, which counts the seconds since the begin of the UNIX-era.
+  var clockTimestampString = Drupal.settings['1'];
+  // The time zone offset in seconds.
+  var clockTimezoneOffsetSeconds = Drupal.settings['2'];
   // The name of the timezone, e.g. 'Europe/London'.
-  var clockTimezoneName = Drupal.settings['2'];
+  var clockTimezoneName = Drupal.settings['3'];
   // Daylight Savings Time information. '1' for yes, '0' for no.
-  var clockDaylightSavingsTime = Drupal.settings['3'];
+  var clockDaylightSavingsTime = Drupal.settings['4'];
   // The name of the offset, e.g. 'GMT'.
-  var clockOffsetName = Drupal.settings['4'];
-  // A PHP date format string.
-  var clockDateFormat = Drupal.settings['5'];
+  var clockOffsetName = Drupal.settings['5'];
+  // A PHP date format string.
+  var clockDateFormat = Drupal.settings['6'];
 
   // Calculate the timestamp with the time zone offset and turn it into milliseconds.
   // JavaScript's time handling is based on milliseconds, while PHP's is based on seconds.
@@ -115,7 +117,7 @@ Drupal.behaviors.clockDisplay = function
   var clock = '';
 
   // Format a given date format string into a proper date string.
-  function formatDate(date, timestamp, dateFormat, timezoneOffsetSeconds, timezoneName, daylightSavingsTime, offsetName) {
+  function formatDate(date, timestamp, dateFormat, timezoneOffsetSeconds, timezoneName, daylightSavingsTime, offsetName) {
     // Initialize the 'formattedDate' variable for later use.
     var formattedDate = '';
 
@@ -187,14 +189,14 @@ Drupal.behaviors.clockDisplay = function
     // Hour-related.
     var hours = date.getHours();
     var hoursLeadingZero = ((hours < 10) ? '0' + hours : hours);
-    if (hours == 0) {
-      var hoursTwelve = (hours + 12);
-    }
-    else if (hours > 12) {
-      var hoursTwelve = (hours - 12);
-    }
-    else {
-      var hoursTwelve = hours;
+    if (hours == 0) {
+      var hoursTwelve = (hours + 12);
+    }
+    else if (hours > 12) {
+      var hoursTwelve = (hours - 12);
+    }
+    else {
+      var hoursTwelve = hours;
     }
     var hoursTwelveLeadingZero = ((hoursTwelve < 10) ? '0' + hoursTwelve : hoursTwelve);
 
@@ -214,10 +216,10 @@ Drupal.behaviors.clockDisplay = function
     }
     else {
       var beatsLeadingZero = beats;
-    }
+    }
 
     // Turn the date format string into an array so each character has its own key.
-    var dateFormatParts = dateFormat.length;
+    var dateFormatParts = dateFormat.length;
     var dateFormatArray = dateFormat.split('');
 
     // Perform the date format conversion for a character.
@@ -227,13 +229,13 @@ Drupal.behaviors.clockDisplay = function
         case '\\':
           formattedDate += dateFormatArray[++i];
           break;
-        // 'am' or 'pm' depending on the time of day.
-        case 'a':
-          formattedDate += ((hours >= 12) ? Drupal.t('pm') : Drupal.t('am'));
-          break;
+        // 'am' or 'pm' depending on the time of day.
+        case 'a':
+          formattedDate += ((hours >= 12) ? Drupal.t('pm') : Drupal.t('am'));
+          break;
         // 'AM' or 'PM' depending on the time of day.
-        case 'A':
-          formattedDate += ((hours >= 12) ? Drupal.t('PM') : Drupal.t('AM'));
+        case 'A':
+          formattedDate += ((hours >= 12) ? Drupal.t('PM') : Drupal.t('AM'));
           break;
         // Swatch-Internet-Time.
         case 'B':
@@ -243,7 +245,7 @@ Drupal.behaviors.clockDisplay = function
         case 'c':
           formattedDate += year + '-' + monthLeadingZero + '-' + dayLeadingZero + 'T' + hoursLeadingZero + ':' + minutesLeadingZero + ':' + secondsLeadingZero + offsetPrefix + offsetHoursLeadingZero + ':' + offsetMinutesLeadingZero;
           break;
-        // Day of month with leading zero, '01' - '31'.
+        // Day of month with leading zero, '01' - '31'.
         case 'd':
           formattedDate += dayLeadingZero;
           break;
@@ -260,24 +262,24 @@ Drupal.behaviors.clockDisplay = function
           formattedDate += monthLongName;
           break;
         // Hours in 12-hour format, '1' - '12'.
-        case 'g':
-          formattedDate += hoursTwelve;
+        case 'g':
+          formattedDate += hoursTwelve;
           break;
         // Hours in 24-hour format, '0' - '23'.
         case 'G':
           formattedDate += hours;
           break;
-        // Hours in 12-hour format with leading zero, '01' - '12'.
-        case 'h':
+        // Hours in 12-hour format with leading zero, '01' - '12'.
+        case 'h':
           formattedDate += hoursTwelveLeadingZero;
           break;
         // Hours in 24-hour format with leading zero, '00' - '23'.
         case 'H':
-          formattedDate += hoursLeadingZero;
+          formattedDate += hoursLeadingZero;
           break;
         // Minutes with leading zero, '00' - '59'.
-        case 'i':
-          formattedDate += minutesLeadingZero;
+        case 'i':
+          formattedDate += minutesLeadingZero;
           break;
         // Daylight Savings Time, '1' or '0'
         case 'I':
@@ -319,9 +321,9 @@ Drupal.behaviors.clockDisplay = function
         case 'r':
           formattedDate += weekdayShortName + ', ' + dayLeadingZero + ' ' + monthShortName + ' ' + year + ' ' + hoursLeadingZero + ':' + minutesLeadingZero + ':' + secondsLeadingZero + ' ' + offsetPrefix + offsetHoursLeadingZero + offsetMinutesLeadingZero;
           break;
-        // Seconds with leading zero.
-        case 's':
-          formattedDate += secondsLeadingZero;
+        // Seconds with leading zero.
+        case 's':
+          formattedDate += secondsLeadingZero;
           break;
         // Appendage for the day of month, e.g. 'st' if the day is '1'.
         case 'S':
@@ -348,7 +350,7 @@ Drupal.behaviors.clockDisplay = function
         case 'W':
           formattedDate += weekNumberLeadingZero;
           break;
-        // Year, e.g. '2001'.
+        // Year, e.g. '2001'.
         case 'Y':
           formattedDate += year;
           break;
@@ -366,57 +368,73 @@ Drupal.behaviors.clockDisplay = function
           formattedDate += timezoneOffsetSeconds;
           break;
         // If the character is not a date formatter, just add it to the output.
-        default:
-          formattedDate += dateFormatArray[i];
-          break;
-      }
+        default:
+          formattedDate += dateFormatArray[i];
+          break;
+      }
     }
     return formattedDate;
   }
-
 
-  // Recalculate the date every second. '.everyTime' is provided by jQuery Timers.
-  $(document).everyTime(1000, function() {
-    // Add 1 second to the timestamp.
-    clockTimestamp = clockTimestamp + 1000;
-    // Format the timestamp into the given format.
-    clockDate = new Date(clockTimestamp);
-    clock = formatDate(clockDate, clockTimestamp, clockDateFormat, clockTimezoneOffsetSeconds, clockTimezoneName, clockDaylightSavingsTime, clockOffsetName);
-    $('div.clock').html(clock);
-  }, 0);
+  if (clockUpdate == '1') {
 
+    // Format the clock.
+    if (clockTimezoneName == 'Local') {
+      var clockDate = new Date();
+    }
+    else {
+      var clockDate = new Date(clockTimestamp);
+    }
+    clock = formatDate(clockDate, clockTimestamp, clockDateFormat, clockTimezoneOffsetSeconds, clockTimezoneName, clockDaylightSavingsTime, clockOffsetName);
+    $('div.clock').html(clock);
+
+    // Recalculate the date every second. '.everyTime' is provided by jQuery Timers.
+    $(document).everyTime(1000, function() {
+      // Add 1 second to the timestamp.
+      clockTimestamp = clockTimestamp + 1000;
+      // Format the timestamp into the given format.
+      if (clockTimezoneName == 'Local') {
+        clockDate = new Date();
+      }
+      else {
+        clockDate = new Date(clockTimestamp);
+      }
+      clock = formatDate(clockDate, clockTimestamp, clockDateFormat, clockTimezoneOffsetSeconds, clockTimezoneName, clockDaylightSavingsTime, clockOffsetName);
+      $('div.clock').html(clock);
+    }, 0);
+  }
 }
 
 /*
  * Hide the select boxes on the clock block configure screen if the specific options are disabled.
  */
-Drupal.behaviors.clockConfigure = function (context) {
-  // Show the custom time zone select list only when 'Custom time zone' is checked.
-  $('div.edit-custom-timezone').addClass('js-hide');
-  function customTimezoneSelect() {
-    var value = $('div.edit-timezone input:checked').val();
-    if (value == '3') {
-      $('div.edit-custom-timezone').show();
-    }
-    else {
-      $('div.edit-custom-timezone').hide();
-    }
-  }
-  $('div.edit-timezone').bind('click', customTimezoneSelect);
-  customTimezoneSelect();
-
-  // Show the custom date format select list only when 'Custom date format' is checked.
-  $('div.edit-custom-date-format').addClass('js-hide');
-  function customDateFormatSelect() {
-    var value = $('div.edit-date-format input:checked').val();
-    if (value == 'custom') {
-      $('div.edit-custom-date-format').show();
-    }
-    else {
-      $('div.edit-custom-date-format').hide();
-    }
-  }
-  $('div.edit-date-format').bind('click', customDateFormatSelect);
-  customDateFormatSelect();
+Drupal.behaviors.clockConfigure = function (context) {
+  // Show the custom time zone select list only when 'Custom time zone' is checked.
+  $('div.edit-custom-timezone').addClass('js-hide');
+  function customTimezoneSelect() {
+    var value = $('div.edit-timezone input:checked').val();
+    if (value == '4') {
+      $('div.edit-custom-timezone').show();
+    }
+    else {
+      $('div.edit-custom-timezone').hide();
+    }
+  }
+  $('div.edit-timezone').bind('click', customTimezoneSelect);
+  customTimezoneSelect();
+
+  // Show the custom date format select list only when 'Custom date format' is checked.
+  $('div.edit-custom-date-format').addClass('js-hide');
+  function customDateFormatSelect() {
+    var value = $('div.edit-date-format input:checked').val();
+    if (value == 'custom') {
+      $('div.edit-custom-date-format').show();
+    }
+    else {
+      $('div.edit-custom-date-format').hide();
+    }
+  }
+  $('div.edit-date-format').bind('click', customDateFormatSelect);
+  customDateFormatSelect();
 }
 
Index: clock.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/clock/clock.module,v
retrieving revision 1.9
diff -d -u -p -r1.9 clock.module
--- clock.module	17 Feb 2010 23:42:10 -0000	1.9
+++ clock.module	21 Mar 2010 19:54:46 -0000
@@ -26,8 +26,9 @@ function clock_block($op = 'list', $delt
           '#default_value' => variable_get('clock_timezone_type', '1'),
           '#options' => array(
             '1' => t('Site time zone'),
-            '2' => t('User time zone'),
-            '3' => t('Custom time zone'),
+            '2' => t('User time zone'),
+            '3' => t('Local time zone'),
+            '4' => t('Custom time zone'),
           ),
           '#prefix' => '<div class="edit-timezone">',
           '#suffix' => '</div>',
@@ -41,8 +42,9 @@ function clock_block($op = 'list', $delt
           '#weight' => 1,
           '#default_value' => variable_get('clock_timezone_type', '1'),
           '#options' => array(
-            '1' => t('Site time zone'),
-            '3' => t('Custom time zone'),
+            '1' => t('Site time zone'),
+            '3' => t('Local time zone'),
+            '4' => t('Custom time zone'),
           ),
           '#prefix' => '<div class="edit-timezone">',
           '#suffix' => '</div>',
@@ -173,10 +175,12 @@ function clock_theme() {
 function theme_clock($timezone = 'UTC', $format = 'g:i a') {
   $output = '';
 
-  $clock_timezone_type = variable_get('clock_timezone_type', 'site');
+  $clock_timezone_type = variable_get('clock_timezone_type', '1');
   switch ($clock_timezone_type) {
     // Site time zone
-    case '1':
+    case '1':
+    // If time zone is set to 'Local' and the user has JS disabled, show the site time zone.
+    case '3':
       $clock_timezone = variable_get('date_default_timezone_name', 'UTC');
       break;
     // User time zone
@@ -184,7 +188,7 @@ function theme_clock($timezone = 'UTC', 
       $clock_timezone = NULL;
       break;
     // Custom time zone
-    case '3':
+    case '4':
       $clock_timezone = variable_get('clock_custom_timezone', 'UTC');
       break;
   }
@@ -196,8 +200,9 @@ function theme_clock($timezone = 'UTC', 
   else {
     $clock_custom_date_format = NULL;
   }
+  $clock_js = variable_get('clock_js', '1');
+  if ($clock_js == '1' || $clock_timezone_type == '3') {
 
-  if (variable_get('clock_js', '1')) {
     // Create variables that are needed for the JavaScript time calculation.
 
     // Create a timestamp.
@@ -205,7 +210,13 @@ function theme_clock($timezone = 'UTC', 
     // Get the time zone offset in seconds.
     $clock_timezone_offset_seconds = date_format_date(date_make_date($date = 'now', $timezone = $clock_timezone), $type = 'custom', $format = 'Z');
     // Get the name of the time zone, e.g. 'Europe/London'.
-    $clock_timezone_name = date_format_date(date_make_date($date = 'now', $timezone = $clock_timezone), $type = 'custom', $format = 'e');
+    if ($clock_timezone_type == '3') {
+      $clock_timezone_name == 'Local';
+    }
+    else {
+      $clock_timezone_name = date_format_date(date_make_date($date = 'now', $timezone = $clock_timezone), $type = 'custom', $format = 'e');
+    }
+
     // Get Daylight Savings Time information. '1' for yes, '0' for no.
     $clock_daylight_savings_time = date_format_date(date_make_date($date = 'now', $timezone = $clock_timezone), $type = 'custom', $format = 'I');
     // Get the name of the offset, e.g. 'GMT'.
@@ -227,13 +238,14 @@ function theme_clock($timezone = 'UTC', 
     }
 
     // Pass the variables to JavaScript.
-    drupal_add_js(array(
-      '0' => $clock_timestamp,
-      '1' => $clock_timezone_offset_seconds,
-      '2' => $clock_timezone_name,
-      '3' => $clock_daylight_savings_time,
-      '4' => $clock_offset_name,
-      '5' => $clock_date_format,
+    drupal_add_js(array(
+      '0' => $clock_js,
+      '1' => $clock_timestamp,
+      '2' => $clock_timezone_offset_seconds,
+      '3' => $clock_timezone_name,
+      '4' => $clock_daylight_savings_time,
+      '5' => $clock_offset_name,
+      '6' => $clock_date_format,
     ), 'setting');
 
     drupal_add_js(drupal_get_path('module', 'clock') . '/jquery.timers.js');
