diff --git a/clock.js b/clock.js index c4196ea..1a1e75b 100644 --- a/clock.js +++ b/clock.js @@ -17,19 +17,25 @@ Drupal.behaviors.clockDisplay = { var dateFormat = Drupal.settings['date_format']; // Whether or not to update the clock continuously. var update = Drupal.settings['update']; - // Whether or not to use the user's local time zone. - var local = Drupal.settings['local'] - // Creates a JavaScript date object, from a specially formatted date string. - // Note that due to JavaScript's inferior time zone handling, time zone - // related date formatters will return the time zone of the Drupal site, not - // the visiting user if the time zone is set to 'Local'. - var date = (Drupal.settings['local'] == 1) ? new Date() : new Date(Drupal.settings['time']); // The name of the offset, e.g. 'GMT'. var offsetName = Drupal.settings['offset_name']; // The time zone offset in seconds. var offsetSeconds = Drupal.settings['offset_seconds']; // Daylight Savings Time information. '1' for yes, '0' for no. var daylightSavingsTime = Drupal.settings['daylight_savings_time']; + // Creates a JavaScript date object, by calculating the difference between + // the target offset and the current offset and adding that to the current + // time. + // Note that due to JavaScript's inferior time zone handling, time zone + // related date formatters will return the time zone of the Drupal site, not + // the visiting user if the time zone is set to 'Local'. + var date = new Date(); + // JavaScript returns the time zone offset reversely signed as PHP, + // therefore we calculate the difference in the absolute values by adding + // the two numbers. + if (!Drupal.settings['local']) { + date = new Date(date.getTime() + (offsetSeconds/60 + date.getTimezoneOffset())*60000); + } // Create an array containing month names. var monthNames = new Array(); diff --git a/clock.module b/clock.module index 3c257a9..ecbb519 100755 --- a/clock.module +++ b/clock.module @@ -264,7 +264,6 @@ function theme_clock($variables) { 'date_format' => $date_format, 'update' => $update, 'local' => $local, - 'time' => $time, 'offset_name' => $offset_name, 'offset_seconds' => $offset_seconds, 'daylight_savings_time' => $daylight_savings_time,