CC-5627 : Check all Application_Common_DateHelper calculations that use timezone.
This commit is contained in:
parent
3a2f9a24b5
commit
3d1f0b0d0e
|
@ -45,23 +45,49 @@ class Application_Common_DateHelper
|
||||||
return gmdate("H:i:s", $this->_dateTime);
|
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
|
* @return DateTime - YYYY-MM-DD 00:00 in station timezone
|
||||||
*/
|
*/
|
||||||
public static function getWeekStartDateTime()
|
public static function getWeekStartDateTime()
|
||||||
{
|
{
|
||||||
$stationTimezone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
|
$now = self::getTodayStationStartDateTime();
|
||||||
$now = new DateTime("now", $stationTimezone);
|
|
||||||
//want it to be the start of the day.
|
|
||||||
$now->setTime(0, 0, 0);
|
|
||||||
|
|
||||||
// our week starts on monday, but php week starts on sunday.
|
// our week starts on monday, but php week starts on sunday.
|
||||||
$day = $now->format('w');
|
$day = $now->format('w');
|
||||||
if ($day == 0) {
|
if ($day == 0) {
|
||||||
$day = 7;
|
$day = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dayDiff = $day - 1;
|
$dayDiff = $day - 1;
|
||||||
if ($dayDiff > 0) {
|
if ($dayDiff > 0) {
|
||||||
$now->sub(new DateInterval("P{$dayDiff}D"));
|
$now->sub(new DateInterval("P{$dayDiff}D"));
|
||||||
|
|
|
@ -80,13 +80,16 @@ class ApiController extends Zend_Controller_Action
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$tz = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
||||||
|
$now = new DateTime("now", $tz);
|
||||||
|
|
||||||
$this->view->calendarInit = array(
|
$this->view->calendarInit = array(
|
||||||
"timestamp" => time(),
|
"timestamp" => time(),
|
||||||
"timezoneOffset" => date("Z"),
|
"timezoneOffset" => $now->format("Z"),
|
||||||
"timeScale" => Application_Model_Preference::GetCalendarTimeScale(),
|
"timeScale" => Application_Model_Preference::GetCalendarTimeScale(),
|
||||||
"timeInterval" => Application_Model_Preference::GetCalendarTimeInterval(),
|
"timeInterval" => Application_Model_Preference::GetCalendarTimeInterval(),
|
||||||
"weekStartDay" => Application_Model_Preference::GetWeekStartDay()
|
"weekStartDay" => Application_Model_Preference::GetWeekStartDay()
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->_helper->json->sendJson(array());
|
$this->_helper->json->sendJson(array());
|
||||||
|
@ -283,7 +286,9 @@ class ApiController extends Zend_Controller_Action
|
||||||
}
|
}
|
||||||
|
|
||||||
// make getNextShows use end of day
|
// 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(
|
$result = array(
|
||||||
"env" => APPLICATION_ENV,
|
"env" => APPLICATION_ENV,
|
||||||
"schedulerTime" => $utcTimeNow,
|
"schedulerTime" => $utcTimeNow,
|
||||||
|
@ -351,13 +356,17 @@ class ApiController extends Zend_Controller_Action
|
||||||
$utcDayStart = $weekStartDateTime->format("Y-m-d H:i:s");
|
$utcDayStart = $weekStartDateTime->format("Y-m-d H:i:s");
|
||||||
for ($i = 0; $i < 14; $i++) {
|
for ($i = 0; $i < 14; $i++) {
|
||||||
|
|
||||||
|
//have to be in station timezone when adding 1 day for daylight savings.
|
||||||
$weekStartDateTime->setTimezone($stationTimezone);
|
$weekStartDateTime->setTimezone($stationTimezone);
|
||||||
$weekStartDateTime->add(new DateInterval('P1D'));
|
$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");
|
$utcDayEnd = $weekStartDateTime->format("Y-m-d H:i:s");
|
||||||
$shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
|
$shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
|
||||||
$utcDayStart = $utcDayEnd;
|
$utcDayStart = $utcDayEnd;
|
||||||
|
|
||||||
Application_Common_DateHelper::convertTimestamps(
|
Application_Common_DateHelper::convertTimestamps(
|
||||||
$shows,
|
$shows,
|
||||||
array("starts", "ends", "start_timestamp","end_timestamp"),
|
array("starts", "ends", "start_timestamp","end_timestamp"),
|
||||||
|
|
Loading…
Reference in New Issue