Index: excellib.class.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/excellib.class.php,v retrieving revision 1.12.2.5 diff -u -r1.12.2.5 excellib.class.php --- excellib.class.php 12 Nov 2009 01:58:05 -0000 1.12.2.5 +++ excellib.class.php 29 Jun 2010 10:08:43 -0000 @@ -194,11 +194,18 @@ function write_date($row, $col, $date, $format=null) { /// Calculate the internal PEAR format $format = $this->MoodleExcelFormat2PearExcelFormat($format); - /// Convert the date to Excel format - $timezone = get_user_timezone_offset(); - $value = ((usertime($date) + (int)($timezone * HOURSECS * 2)) / 86400) + 25569; + /// Convert the unix timestamp date to Excel date format + $date = usertime($date); + $seconds_in_day = 86400; + $utime_excel_diff = $seconds_in_day * 25569; + $exceldate = ($date + $utime_excel_diff) / $seconds_in_day; + // Adjust the time offset + $this_tz = new DateTimeZone(date_default_timezone_get()); + $now = new DateTime("now", $this_tz); + $offset = $this_tz->getOffset($now); + $exceldate = $exceldate + ($offset/$seconds_in_day); /// Add the date safely to the PEAR Worksheet - $this->pear_excel_worksheet->writeNumber($row, $col, $value, $format); + $this->pear_excel_worksheet->writeNumber($row, $col, $exceldate, $format); } /**