Permalink
Browse files

Merge remote-tracking branch 'magicmonkey/JOINDIN-169'

  • Loading branch information...
2 parents 7fc4a5b + 2727c5a commit 71db711ad8efa752e1773c6319b0c5131a13fc2e @lornajane lornajane committed May 5, 2012
Showing with 13 additions and 34 deletions.
  1. +8 −15 src/system/application/libraries/Timezone.php
  2. +5 −19 src/system/application/models/talks_model.php
@@ -12,18 +12,6 @@ public function __construct() {
$this->CI=&get_instance();
}
- /**
- * Return the difference from UTC for my machine
- * @param $tz integer Timezone string
- */
- private function _getMyTimeDiff($tz=null) {
- if (!$tz) { $tz=date_default_timezone_get(); }
- $here = new DateTimeZone($tz);
- $there = new DateTimeZone('UTC');
- $offset = $here->getOffset(new DateTime("now", $here))-$there->getOffset(new DateTime("now", $there));
-
- return $offset;
- }
/**
* Find the local time at the event...
* @param $evt_offset integer Event's offset from UTC
@@ -76,17 +64,18 @@ public function getDatetimeFromUnixtime($unixtime, $timezone) {
}
$datetime->setTimezone($tz);
+/* Commented out as it appears to be causing a DST bug - see JOINDIN-169 in Jira
// How much wrong will ->format("U") be if I do it now, due to DST changes?
// Only needed until PHP Bug #51051 delivers a better method
$unix_offset1 = $tz->getOffset($datetime);
$unix_offset2 = $tz->getOffset(new DateTime());
$unix_correction = $unix_offset1 - $unix_offset2;
-
// create datetime object corrected for DST offset
$timestamp = $unixtime + $unix_correction;
-
$datetime = new DateTime("@{$timestamp}");
$datetime->setTimezone($tz);
+*/
+
return $datetime;
}
@@ -106,13 +95,17 @@ public function UnixtimeForTimeInTimezone($timezone, $year, $month, $day, $hour,
$dateObj->setDate($year, $month, $day);
$dateObj->setTime($hour, $minute, $second);
+ $unixTimestamp = $dateObj->format("U") - $unix_correction;
+
+/* Commented out as it appears to be causing a DST bug - see JOINDIN-169 in Jira
// How much wrong will ->format("U") be if I do it now, due to DST changes?
// Only needed until PHP Bug #51051 delivers a better method
$unix_offset1 = $tz->getOffset($dateObj);
$unix_offset2 = $tz->getOffset(new DateTime());
$unix_correction = $unix_offset1 - $unix_offset2;
+ $unixTimestamp = $unix_timestamp - $unix_correction;
+*/
- $unixTimestamp = $dateObj->format("U") - $unix_correction;
return $unixTimestamp;
}
@@ -504,34 +504,20 @@ public function search($term, $start, $end) {
* @return the amended array with additional fields
*/
public function setDisplayFields($det) {
+ $this->load->library('timezone');
+
$retval = array();
foreach ($det as $talk) {
- // create datetime object
- $talk_datetime = new DateTime("@{$talk->date_given}");
// if a timezone is specified, adjust times
if (!empty($talk->event_tz_cont) && !empty($talk->event_tz_place)) {
- $event_timezone = new DateTimeZone($talk->event_tz_cont . '/' . $talk->event_tz_place);
+ $a = $talk->event_tz_cont . '/' . $talk->event_tz_place;
} else {
- $event_timezone = new DateTimeZone('UTC');
+ $a = 'UTC';
}
- $talk_datetime->setTimezone($event_timezone);
-
-
- // How much wrong will ->format("U") be if I do it now, due to DST changes?
- // Only needed until PHP Bug #51051 delivers a better method
- $unix_offset1 = $event_timezone->getOffset($talk_datetime);
- $unix_offset2 = $event_timezone->getOffset(new DateTime());
- $unix_correction = $unix_offset1 - $unix_offset2;
-
-
- // create datetime object corrected for DST offset
- $timestamp = $talk->date_given + $unix_correction;
- $talk_datetime = new DateTime("@{$timestamp}");
- $talk_datetime->setTimezone($event_timezone);
-
+ $talk_datetime = $this->timezone->getDatetimeFromUnixtime($talk->date_given, $a);
// set a datetime string, ignoring talks at midnight and assuming they are without times
if ($talk_datetime->format('H') != '0') {

0 comments on commit 71db711

Please sign in to comment.