CC-2965: Frontend widget displays shows in UTC time
Not only were frontend widgets showing UTC time, the SQL query was also comparing UTC timestamp with local timestamps, causing widgets to display shows in the wrong day, etc. Another problem was that "On air today" widget was simply calling GetNextShows which returns shows within next 48 hours. Fixed by: 1. Under models/Show.php: In the GetCurrentShow/GetNextShows/GetShowsByDayOfWeek functions, added code to convert UTC timestamp to local timestamp or vice versa, depending on which one is more suitable, in SQL queries, thus removing inconsistency in timezones. Also, before returning query result, added code to convert result to local timezone. In GetNextShows, added an optional parameter endTime to limit the interval of shows to get. This is useful for the "On air today" widget. 2. Under models/DateHelper.php: Added a few timezone functions to help converting timezones easier in Show.php. 3. Under controller/ApiController.php: Added todayInfoAction which is to be used by "On Air Today" widget.
This commit is contained in:
parent
9506161b70
commit
6ffecf80c8
4 changed files with 201 additions and 40 deletions
|
@ -56,6 +56,21 @@ class Application_Model_DateHelper
|
|||
$this->_dateTime = strtotime($dateString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate and return the timestamp for end of day today
|
||||
* in local time.
|
||||
*
|
||||
* For example, if local time is 2PM on 2011-11-01,
|
||||
* then the function would return 2011-11-02 00:00:00
|
||||
*
|
||||
* @return End of day timestamp in local timezone
|
||||
*/
|
||||
function getDayEndTimestamp() {
|
||||
$dateTime = new DateTime($this->getDate());
|
||||
$dateTime->add(new DateInterval('P1D'));
|
||||
return $dateTime->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the epoch timestamp difference from "now" to the beginning of today.
|
||||
*/
|
||||
|
@ -79,6 +94,43 @@ class Application_Model_DateHelper
|
|||
return $this->_dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset in seconds, between local and UTC timezones.
|
||||
* E.g., if local timezone is -4, this function
|
||||
* returns -14400.
|
||||
*
|
||||
* @return type offset in int, between local and UTC timezones
|
||||
*/
|
||||
function getLocalTimeZoneOffset() {
|
||||
$dateTime = new DateTime("@".$this->_dateTime, new DateTimeZone("UTC"));
|
||||
$timezone = new DateTimeZone(date_default_timezone_get());
|
||||
return $timezone->getOffset($dateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset hour in int, between local and UTC timezones.
|
||||
* E.g., if local timezone is -4:30, this function
|
||||
* returns -4.
|
||||
*
|
||||
* @return type offset hour in int, between local and UTC timezones
|
||||
*/
|
||||
function getLocalOffsetHour() {
|
||||
$offset = $this->getLocalTimeZoneOffset();
|
||||
return (int)($offset / 3600);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset minute in int, between local and UTC timezones.
|
||||
* E.g., if local timezone is -4:30, this function
|
||||
* returns -30.
|
||||
*
|
||||
* @return type offset minute in int, between local and UTC timezones
|
||||
*/
|
||||
function getLocalOffsetMinute() {
|
||||
$offset = $this->getLocalTimeZoneOffset();
|
||||
return (int)(($offset % 3600) / 60);
|
||||
}
|
||||
|
||||
public static function TimeDiff($time1, $time2)
|
||||
{
|
||||
return strtotime($time2) - strtotime($time1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue