diff --git a/clock.js b/clock.js index b4319c0..aedf9b9 100644 --- a/clock.js +++ b/clock.js @@ -11,28 +11,29 @@ Drupal.behaviors.clockDisplay = function (context) { // Gets the correct variables from PHP. // Whether or not to update the clock continuously var update = Drupal.settings['update']; - // Whether or not to use the client's local time. - var local = Drupal.settings['local']; - // Creates a JavaScript date object, from a specially formatted date string. - var date = new Date(Drupal.settings['time']); // The time zone offset in seconds. var offsetSeconds = Drupal.settings['offset_seconds']; // The name of the timezone, e.g. 'Europe/London'. var timezoneName = Drupal.settings['timezone_name']; - // If time zone is set to 'Local' overwrite the date. - // 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 (local) { - date = new Date(); - } - // Daylight Savings Time information. '1' for yes, '0' for no. var daylightSavingsTime = Drupal.settings['daylight_savings_time']; // The name of the offset, e.g. 'GMT'. var offsetName = Drupal.settings['offset_name']; // A PHP date format string. var dateFormat = Drupal.settings['date_format']; + // 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 7d3fe9a..81a4d3f 100755 --- a/clock.module +++ b/clock.module @@ -286,7 +286,6 @@ function theme_clock($timezone, $date_format, $js) { drupal_add_js(array( 'update' => $js, 'local' => isset($local) ? TRUE : FALSE, - 'time' => $time, 'offset_seconds' => $offset_seconds, 'timezone_name' => $timezone, 'daylight_savings_time' => $daylight_savings_time,