CC-5627 : Check all Application_Common_DateHelper calculations that use timezone.

This commit is contained in:
Naomi 2013-12-10 17:41:59 -05:00
parent 3a2f9a24b5
commit 3d1f0b0d0e
2 changed files with 47 additions and 12 deletions

View File

@ -45,23 +45,49 @@ class Application_Common_DateHelper
return gmdate("H:i:s", $this->_dateTime);
}
/**
*
* @return DateTime - YYYY-MM-DD 00:00 in station timezone of today
*/
public static function getTodayStationStartDateTime()
{
$stationTimezone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
$now = new DateTime("now", $stationTimezone);
$now->setTime(0, 0, 0);
return $now;
}
/**
*
* @return DateTime - YYYY-MM-DD 00:00 in station timezone of tomorrow
*/
public static function getTodayStationEndDateTime()
{
$stationTimezone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
$now = new DateTime("now", $stationTimezone);
$now->add(new DateInterval("P1D"));
$now->setTime(0, 0, 0);
return $now;
}
/**
*
* @return DateTime - YYYY-MM-DD 00:00 in station timezone
*/
public static function getWeekStartDateTime()
{
$stationTimezone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
$now = new DateTime("now", $stationTimezone);
//want it to be the start of the day.
$now->setTime(0, 0, 0);
$now = self::getTodayStationStartDateTime();
// our week starts on monday, but php week starts on sunday.
$day = $now->format('w');
if ($day == 0) {
$day = 7;
}
$dayDiff = $day - 1;
if ($dayDiff > 0) {
$now->sub(new DateInterval("P{$dayDiff}D"));

View File

@ -80,13 +80,16 @@ class ApiController extends Zend_Controller_Action
return;
}
$tz = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$now = new DateTime("now", $tz);
$this->view->calendarInit = array(
"timestamp" => time(),
"timezoneOffset" => date("Z"),
"timeScale" => Application_Model_Preference::GetCalendarTimeScale(),
"timeInterval" => Application_Model_Preference::GetCalendarTimeInterval(),
"weekStartDay" => Application_Model_Preference::GetWeekStartDay()
"timestamp" => time(),
"timezoneOffset" => $now->format("Z"),
"timeScale" => Application_Model_Preference::GetCalendarTimeScale(),
"timeInterval" => Application_Model_Preference::GetCalendarTimeInterval(),
"weekStartDay" => Application_Model_Preference::GetWeekStartDay()
);
$this->_helper->json->sendJson(array());
@ -283,7 +286,9 @@ class ApiController extends Zend_Controller_Action
}
// make getNextShows use end of day
$utcTimeEnd = Application_Common_DateHelper::GetDayEndTimestampInUtc();
$end = Application_Common_DateHelper::getTodayStationEndDateTime();
$end->setTimezone(new DateTimeZone("UTC"));
$utcTimeEnd = $end->format("Y-m-d H:i:s");
$result = array(
"env" => APPLICATION_ENV,
"schedulerTime" => $utcTimeNow,
@ -351,13 +356,17 @@ class ApiController extends Zend_Controller_Action
$utcDayStart = $weekStartDateTime->format("Y-m-d H:i:s");
for ($i = 0; $i < 14; $i++) {
//have to be in station timezone when adding 1 day for daylight savings.
$weekStartDateTime->setTimezone($stationTimezone);
$weekStartDateTime->add(new DateInterval('P1D'));
//convert back to UTC to get the actual timestamp used for search.
$weekStartDateTime->setTimezone($utcTimezone);
$utcDayEnd = $weekStartDateTime->format("Y-m-d H:i:s");
$shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
$utcDayStart = $utcDayEnd;
Application_Common_DateHelper::convertTimestamps(
$shows,
array("starts", "ends", "start_timestamp","end_timestamp"),