Index: install.php
===================================================================
RCS file: /cvs/drupal/drupal/install.php,v
retrieving revision 1.152
diff -u -9 -p -r1.152 install.php
--- install.php	4 Feb 2009 04:42:26 -0000	1.152
+++ install.php	6 Feb 2009 23:13:45 -0000
@@ -27,18 +27,22 @@ define('MAINTENANCE_MODE', 'install');
 function install_main() {
   // The user agent header is used to pass a database prefix in the request when
   // running tests. However, for security reasons, it is imperative that no
   // installation be permitted using such a prefix.
   if (preg_match("/^simpletest\d+$/", $_SERVER['HTTP_USER_AGENT'])) {
     header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
     exit;
   }
 
+  global $system_default_timezone;
+  // The default timezone set in php.ini is reset during bootstrap.
+  $system_default_timezone = @date_default_timezone_get();
+
   require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
   drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
 
   // This must go after drupal_bootstrap(), which unsets globals!
   global $profile, $install_locale, $conf;
 
   require_once DRUPAL_ROOT . '/modules/system/system.install';
   require_once DRUPAL_ROOT . '/includes/file.inc';
 
@@ -1076,22 +1080,23 @@ function install_configure_form(&$form_s
     '#size' => 25,
     '#weight' => 0,
   );
 
   $form['server_settings'] = array(
     '#type' => 'fieldset',
     '#title' => st('Server settings'),
     '#collapsible' => FALSE,
   );
+  global $system_default_timezone;
   $form['server_settings']['date_default_timezone'] = array(
     '#type' => 'select',
     '#title' => st('Default time zone'),
-    '#default_value' => date_default_timezone_get(),
+    '#default_value' => $system_default_timezone,
     '#options' => system_time_zones(),
     '#description' => st('By default, dates in this site will be displayed in the chosen time zone.'),
     '#weight' => 5,
     '#attributes' => array('class' => 'timezone-detect'),
   );
 
   $form['server_settings']['clean_url'] = array(
     '#type' => 'radios',
     '#title' => st('Clean URLs'),
Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.269
diff -u -9 -p -r1.269 bootstrap.inc
--- includes/bootstrap.inc	31 Jan 2009 16:50:56 -0000	1.269
+++ includes/bootstrap.inc	6 Feb 2009 23:13:46 -0000
@@ -1172,18 +1172,26 @@ function _drupal_bootstrap($phase) {
       }
       else {
         $user = drupal_anonymous_user();
       }
       break;
 
     case DRUPAL_BOOTSTRAP_VARIABLES:
       // Initialize configuration variables, using values from settings.php if available.
       $conf = variable_init(isset($conf) ? $conf : array());
+      if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) {
+        $timezone = $user->timezone;
+      }
+      else {
+        $timezone = variable_get('date_default_timezone', 'UTC');
+      }
+      date_default_timezone_set($timezone);
+
       break;
 
     case DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE:
       $cache_mode = variable_get('cache', CACHE_DISABLED);
       // Get the page from the cache.
       $cache = $cache_mode == CACHE_DISABLED ? FALSE : page_get_cache(TRUE);
       // If the skipping of the bootstrap hooks is not enforced, call hook_boot.
       if (!is_object($cache) || $cache_mode != CACHE_AGGRESSIVE) {
         // Load module handling.
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.864
diff -u -9 -p -r1.864 common.inc
--- includes/common.inc	5 Feb 2009 01:21:16 -0000	1.864
+++ includes/common.inc	6 Feb 2009 23:13:46 -0000
@@ -1532,24 +1532,19 @@ function format_interval($timestamp, $gr
  *   Optional language code to translate to a language other than what is used
  *   to display the page.
  * @return
  *   A translated date string in the requested format.
  */
 function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
   static $timezones = array();
   if (!isset($timezone)) {
     global $user;
-    if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) {
-      $timezone = $user->timezone;
-    }
-    else {
-      $timezone = variable_get('date_default_timezone', 'UTC');
-    }
+    $timezone = date_default_timezone_get();
   }
   // Store DateTimeZone objects in an array rather than repeatedly
   // contructing identical objects over the life of a request.
   if (!isset($timezones[$timezone])) {
     $timezones[$timezone] = timezone_open($timezone);
   }
 
   switch ($type) {
     case 'small':
Index: includes/session.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/session.inc,v
retrieving revision 1.65
diff -u -9 -p -r1.65 session.inc
--- includes/session.inc	19 Jan 2009 10:46:50 -0000	1.65
+++ includes/session.inc	6 Feb 2009 23:13:46 -0000
@@ -221,29 +221,38 @@ function drupal_get_session($name = NULL
 function drupal_set_session($name, $value) {
   drupal_session_start();
   $_SESSION[$name] = $value;
 }
 
 /**
  * Called when an anonymous user becomes authenticated or vice-versa.
  */
 function drupal_session_regenerate() {
+  global $user;
+
   $old_session_id = session_id();
   extract(session_get_cookie_params());
   // Set "httponly" to TRUE to reduce the risk of session stealing via XSS.
   session_set_cookie_params($lifetime, $path, $domain, $secure, TRUE);
   session_regenerate_id();
   db_update('sessions')
     ->fields(array(
       'sid' => session_id()
     ))
     ->condition('sid', $old_session_id)
     ->execute();
+  if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) {
+    $timezone = $user->timezone;
+  }
+  else {
+    $timezone = variable_get('date_default_timezone', 'UTC');
+  }
+  date_default_timezone_set($timezone);
 }
 
 /**
  * Counts how many users are active on the site.
  *
  * Counts how many users have sessions which have been active since the
  * specified time. Can count either anonymous sessions or
  * authenticated sessions.
  *
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.83
diff -u -9 -p -r1.83 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	6 Feb 2009 00:30:36 -0000	1.83
+++ modules/simpletest/drupal_web_test_case.php	6 Feb 2009 23:13:46 -0000
@@ -811,18 +811,19 @@ class DrupalWebTestCase {
    * @param ...
    *   List of modules to enable for the duration of the test.
    */
   protected function setUp() {
     global $db_prefix, $user;
 
     // Store necessary current values before switching to prefixed database.
     $this->originalPrefix = $db_prefix;
     $clean_url_original = variable_get('clean_url', 0);
+    $date_default_timezone_original = variable_get('date_default_timezone', 0);
 
     // Generate temporary prefixed database to ensure that tests have a clean starting point.
     $db_prefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
 
     include_once DRUPAL_ROOT . '/includes/install.inc';
     drupal_install_system();
 
     $this->preloadRegistry();
 
@@ -851,18 +852,19 @@ class DrupalWebTestCase {
     $this->originalUser = $user;
     drupal_save_session(FALSE);
     $user = user_load(array('uid' => 1));
 
     // Restore necessary variables.
     variable_set('install_profile', 'default');
     variable_set('install_task', 'profile-finished');
     variable_set('clean_url', $clean_url_original);
     variable_set('site_mail', 'simpletest@example.com');
+    variable_set('date_default_timezone', $date_default_timezone_original);
 
     // Use temporary files directory with the same prefix as database.
     $this->originalFileDirectory = file_directory_path();
     variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix);
     $directory = file_directory_path();
     file_check_directory($directory, FILE_CREATE_DIRECTORY); // Create the files directory.
     set_time_limit($this->timeLimit);
   }
 
