CC-3067: Shows in frontend widgets appear on the wrong day after changing timezone

- Converting times to UTC timezone in ApiController before sending them to model functions

- Added utility functions in DateHelper.php

- GetShowsByDayOfWeek has been removed due to bugs caused by using local timezone
based variable like $day, which represents day of the week in local time, in db query,
which has times saved in UTC timezone. Converting stuff like day of the week from local
to UTC is messy. GetNextShows(...) can do the job so WeekInfoAction now uses it instead
This commit is contained in:
Yuchen Wang 2011-11-21 18:03:56 -05:00
parent eb93004b66
commit 86729475f6
4 changed files with 62 additions and 87 deletions

View file

@ -29,7 +29,7 @@ class Application_Model_DateHelper
/**
* Get date of object construction in the format
* YY:mm:dd
* YYYY-MM-DD
*/
function getDate()
{
@ -44,6 +44,19 @@ class Application_Model_DateHelper
{
return gmdate("H:i:s", $this->_dateTime);
}
/**
* Get the week start date of this week in the format
* YYYY-MM-DD
*
* @return String - week start date
*/
function getWeekStartDate()
{
$startDate = date('w') == 0 ? date('Y-m-d') : date('Y-m-d', strtotime('last sunday'));
$startDateTime = new DateTime($startDate);
return $startDateTime->format('Y-m-d H:i:s');
}
/**
* Set the internal timestamp of the object.
@ -63,11 +76,16 @@ class Application_Model_DateHelper
*
* @return End of day timestamp in local timezone
*/
function getDayEndTimestamp() {
$dateTime = new DateTime($this->getDate(), new DateTimeZone("UTC"));
public static function GetDayEndTimestamp($time = "") {
$dateTime = $time == "" ? new DateTime(date("Y-m-d")) : new DateTime($time);
$dateTime->add(new DateInterval('P1D'));
return $dateTime->format('Y-m-d H:i:s');
}
public static function GetDayEndTimestampInUtc($time = "") {
$dayEndTimestamp = Application_Model_DateHelper::GetDayEndTimestamp($time);
return Application_Model_DateHelper::ConvertToUtcDateTime($dayEndTimestamp);
}
/**
* Find the epoch timestamp difference from "now" to the beginning of today.
@ -265,5 +283,11 @@ class Application_Model_DateHelper
return $p_dateString;
return self::ConvertToLocalDateTime($p_dateString)->format($p_format);
}
public static function ConvertToUtcDateTimeString($p_dateString, $p_format="Y-m-d H:i:s"){
if (is_null($p_dateString) || strlen($p_dateString) == 0)
return $p_dateString;
return self::ConvertToUtcDateTime($p_dateString)->format($p_format);
}
}