Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.537.2.14 diff -u -r1.537.2.14 common.inc --- includes/common.inc 18 Oct 2006 20:14:42 -0000 1.537.2.14 +++ includes/common.inc 3 Nov 2006 05:53:39 -0000 @@ -891,18 +891,22 @@ * A translated date string in the requested format. */ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL) { + global $user; + if (!isset($timezone)) { - global $user; if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) { $timezone = $user->timezone; + $timestamp += $timezone; } else { $timezone = variable_get('date_default_timezone', 0); + $timestamp += $timezone; + if (variable_get('daylight_saving_time', 0) && drupal_is_dst($timestamp)) { + $timestamp += 3600; + } } } - $timestamp += $timezone; - switch ($type) { case 'small': $format = variable_get('date_format_short', 'm/d/Y - H:i'); @@ -1470,3 +1474,68 @@ } } } + + +/** + * Check if time is in Daylight Savings Time + * + * @param + * $timestamp a timestamp + * @return + * 0 or 1 + */ +function drupal_is_dst($timestamp) { + $year = date('Y', $timestamp); + $timezone = variable_get('date_default_timezone', 0); + + // Information on Daylight Saving time was obtained from http://webexhibits.org/daylightsaving/g.html + switch (variable_get('daylight_saving_time', 0)) { + case 0: + return 0; + case 1: // EU and other European countries + // start of DST (last Sunday in March 1 am GMT) + $dststart = strtotime("-1 week sunday GMT", strtotime("1 april $year GMT")) + 3600; + // end of DST in Europe (last Sunday in October 1 am GMT) + $dstend = strtotime("-1 week sunday GMT", strtotime("1 november $year GMT")) + 3600; + break; + case 2: // Russian Federation + // start of DST (last Sunday in March 2 am local time) + $dststart = strtotime("-1 week sunday GMT", strtotime("1 april $year GMT")) + 7200 + $timezone; + // end of DST (last Sunday in October 2 am local time) + $dstend = strtotime("-1 week sunday GMT", strtotime("1 november $year GMT")) + 7200 + $timezone; + break; + case 3: // Northern America (where applicable) + // start of DST (where applicable) (first Sunday in April 2 am local time) + $dststart = strtotime("1 week sunday GMT", strtotime("1 april $year GMT")) + 7200 + $timezone; + // end of DST (where applicable) (last Sunday in October 2 am local time) + $dstend = strtotime("-1 week sunday GMT", strtotime("1 november $year GMT")) + 7200 + $timezone; + break; + case 4: // Australia + // start of DST (last Sunday in October at 2am) + $dststart = strtotime("-1 week sunday GMT", strtotime("1 november $year GMT")) + 7200 + $timezone; + // end of DST (last Sunday in March at 2am) + $dstend = strtotime("-1 week sunday GMT", strtotime("1 april $year GMT")) + 7200 + $timezone; + if ($dstend < $timestamp) { + $dstend = strtotime("+1 year", $dstend); + } + elseif ($dststart > $timestamp) { + $dststart = strtotime("-1 year", $dststart); + } + break; + case 5: // New Zealand + // start of DST (last Sunday in October) + $dststart = strtotime("-1 week sunday GMT", strtotime("1 november $year GMT")) + 7200 + $timezone; + // end of DST (third Sunday in March) + $dstend = strtotime("3 week sunday GMT", strtotime("1 march $year GMT")) + 7200 + $timezone; + if ($dstend < $timestamp) { + $dstend = strtotime("+1 year", $dstend); + } + elseif ($dststart > $timestamp) { + $dststart = strtotime("-1 year", $dststart); + } + break; + } + + return ($dststart <= $timestamp && $timestamp <= $dstend); +} + Index: modules/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/Attic/node.module,v retrieving revision 1.641.2.17 diff -u -r1.641.2.17 node.module --- modules/node.module 18 Oct 2006 20:14:42 -0000 1.641.2.17 +++ modules/node.module 3 Nov 2006 05:53:41 -0000 @@ -1605,6 +1605,12 @@ if (!isset($node->date)) { $node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O'); + if (!variable_get('configurable_timezones', 1)) { + if (drupal_is_dst($node->created)) { + $node->created -= 3600; + $node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O'); + } + } } } node_invoke($node, 'prepare'); Index: modules/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/Attic/system.module,v retrieving revision 1.320.2.12 diff -u -r1.320.2.12 system.module --- modules/system.module 18 Oct 2006 20:37:08 -0000 1.320.2.12 +++ modules/system.module 3 Nov 2006 05:53:43 -0000 @@ -399,6 +399,15 @@ // Date settings: $zones = _system_zonelist(); + // Daylight saving time settings + $dst = array(t('None'), + t('EU and other European countries'), + t('Russian Federation'), + t('Northern America (where applicable)'), + t('Australia (where applicable)'), + t('New Zealand') + ); + // Date settings: possible date formats $dateshort = array('Y-m-d H:i','m/d/Y - H:i', 'd/m/Y - H:i', 'Y/m/d - H:i', 'd.m.Y - H:i', 'm/d/Y - g:ia', 'd/m/Y - g:ia', 'Y/m/d - g:ia', @@ -428,6 +437,11 @@ '#options' => $zones, '#description' => t('Select the default site time zone.') ); + $form['dates']['daylight_saving_time'] = array( + '#type' => 'radios', '#title' => t('Daylight saving time '), '#default_value' => variable_get('daylight_saving_time', 0), '#options' => $dst, + '#description' => t('Select the Daylight saving time setting (DST) appropriate for your site. Takes only effect if configurable time zones are disabled. If chosing a setting here, make sure you set your default time zone to standard time.') + ); + $form['dates']['configurable_timezones'] = array( '#type' => 'radios', '#title' => t('Configurable time zones'), '#default_value' => variable_get('configurable_timezones', 1), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Enable or disable user-configurable time zones. When enabled, users can set their own time zone and dates will be updated accordingly.')