cc-2683: not using utc time

-top panel now start at correct time
This commit is contained in:
martin 2011-08-16 15:04:41 -04:00
parent 41fd5f2543
commit 8aa26b2eb0
4 changed files with 55 additions and 51 deletions

View File

@ -17,26 +17,26 @@ class Application_Model_Dashboard
return null;
} else {
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"]));
"starts"=>$row[0]["starts"],
"ends"=>$row[0]["ends"]);
}
} else {
if (count($row) == 0){
//last item is a show instance
return array("name"=>$showInstance->getName(),
"starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()),
"ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd()));
"starts"=>$showInstance->getShowStart(),
"ends"=>$showInstance->getShowEnd());
} else {
//return the one that started later.
if ($row[0]["starts"] >= $showInstance->getShowStart()){
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"]));
"starts"=>$row[0]["starts"],
"ends"=>$row[0]["ends"]);
} else {
return array("name"=>$showInstance->getName(),
"starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()),
"ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd()));
"starts"=>$showInstance->getShowStart(),
"ends"=>$showInstance->getShowEnd());
}
}
}
@ -49,7 +49,7 @@ class Application_Model_Dashboard
//name. Else return the last item from the schedule.
$row = array();
$showInstance = ShowInstance::GetCurrentShowInstance($p_timeNow);
$showInstance = ShowInstance::GetCurrentShowInstance($p_timeNow);
if (!is_null($showInstance)){
$instanceId = $showInstance->getShowInstanceId();
$row = Schedule::GetCurrentScheduleItem($p_timeNow, $instanceId);
@ -63,21 +63,21 @@ class Application_Model_Dashboard
* in the future.
*/
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"]));
"starts"=>$row[0]["starts"],
"ends"=>$row[0]["ends"]);
}
} else {
if (count($row) == 0){
//last item is a show instance
return array("name"=>$showInstance->getName(),
"starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()),
"ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd()),
"starts"=>$showInstance->getShowStart(),
"ends"=>$showInstance->getShowEnd(),
"media_item_played"=>false,
"record"=>$showInstance->isRecorded());
} else {
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"]),
"starts"=>$row[0]["starts"],
"ends"=>$row[0]["ends"],
"media_item_played"=>$row[0]["media_item_played"],
"record"=>0);
}
@ -98,26 +98,26 @@ class Application_Model_Dashboard
return null;
} else {
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"]));
"starts"=>$row[0]["starts"],
"ends"=>$row[0]["ends"]);
}
} else {
if (count($row) == 0){
//last item is a show instance
return array("name"=>$showInstance->getName(),
"starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()),
"ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd()));
"starts"=>$showInstance->getShowStart(),
"ends"=>$showInstance->getShowEnd());
} else {
//return the one that starts sooner.
if ($row[0]["starts"] <= $showInstance->getShowStart()){
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"]));
"starts"=>$row[0]["starts"],
"ends"=>$row[0]["ends"]);
} else {
return array("name"=>$showInstance->getName(),
"starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()),
"ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd()));
"starts"=>$showInstance->getShowStart(),
"ends"=>$showInstance->getShowEnd());
}
}
}

View File

@ -2,11 +2,11 @@
class DateHelper
{
private $_timestamp;
private $_dateTime;
function __construct()
{
$this->_timestamp = date("U");
$this->_dateTime = date("U");
}
/**
@ -15,7 +15,7 @@ class DateHelper
*/
function getTimestamp()
{
return date("Y-m-d H:i:s", $this->_timestamp);
return date("Y-m-d H:i:s", $this->_dateTime);
}
/**
@ -24,7 +24,7 @@ class DateHelper
*/
function getUtcTimestamp()
{
$dateTime = new DateTime("@".$this->_timestamp);
$dateTime = new DateTime("@".$this->_dateTime);
$dateTime->setTimezone(new DateTimeZone("UTC"));
return $dateTime->format("Y-m-d H:i:s");
@ -36,7 +36,7 @@ class DateHelper
*/
function getDate()
{
return date("Y-m-d", $this->_timestamp);
return date("Y-m-d", $this->_dateTime);
}
/**
@ -45,7 +45,7 @@ class DateHelper
*/
function getTime()
{
return date("H:i:s", $this->_timestamp);
return date("H:i:s", $this->_dateTime);
}
/**
@ -53,28 +53,30 @@ class DateHelper
*/
function setDate($dateString)
{
$this->_timestamp = strtotime($dateString);
$this->_dateTime = strtotime($dateString);
}
/**
*
* Enter description here ...
* Find the epoch timestamp difference from "now" to the beginning of today.
*/
function getNowDayStartDiff()
{
$dayStartTS = strtotime(date("Y-m-d", $this->_timestamp));
return $this->_timestamp - $dayStartTS;
$dayStartTs = ((int)($this->_dateTime/86400))*86400;
return $this->_dateTime - $dayStartTs;
}
/**
* Find the epoch timestamp difference from "now" to the end of today.
*/
function getNowDayEndDiff()
{
$dayEndTS = strtotime(date("Y-m-d", $this->_timestamp+(86400)));
return $dayEndTS - $this->_timestamp;
$dayEndTs = ((int)(($this->_dateTime+86400)/86400))*86400;
return $dayEndTs - $this->_dateTime;
}
function getEpochTime()
{
return $this->_timestamp;
return $this->_dateTime;
}
public static function TimeDiff($time1, $time2)
@ -112,31 +114,31 @@ class DateHelper
* format "hh:mm:ss". But when dealing with show times, we
* do not care about the seconds.
*
* @param int $p_timestamp
* @param int $p_dateTime
* The value which to format.
* @return int
* The timestamp with the new format "hh:mm", or
* the original input parameter, if it does not have
* the correct format.
*/
public static function removeSecondsFromTime($p_timestamp)
public static function removeSecondsFromTime($p_dateTime)
{
//Format is in hh:mm:ss. We want hh:mm
$timeExplode = explode(":", $p_timestamp);
$timeExplode = explode(":", $p_dateTime);
if (count($timeExplode) == 3)
return $timeExplode[0].":".$timeExplode[1];
else
return $p_timestamp;
return $p_dateTime;
}
public static function getDateFromTimestamp($p_timestamp){
$explode = explode(" ", $p_timestamp);
public static function getDateFromTimestamp($p_dateTime){
$explode = explode(" ", $p_dateTime);
return $explode[0];
}
public static function getTimeFromTimestamp($p_timestamp){
$explode = explode(" ", $p_timestamp);
public static function getTimeFromTimestamp($p_dateTime){
$explode = explode(" ", $p_dateTime);
return $explode[1];
}

View File

@ -55,16 +55,16 @@ class Application_Model_Nowplaying
public static function GetDataGridData($viewType, $dateString){
if ($viewType == "now"){
$date = new DateHelper;
$timeNow = $date->getTimestamp();
$dateTime = new DateTime("now", new DateTimeZone("UTC"));
$timeNow = $dateTime->format("Y-m-d H:i:s");
$startCutoff = 60;
$endCutoff = 86400; //60*60*24 - seconds in a day
} else {
$date = new DateHelper;
$time = $date->getTime();
$date->setDate($dateString." ".$time);
$timeNow = $date->getTimestamp();
$timeNow = $date->getUtcTimestamp();
$startCutoff = $date->getNowDayStartDiff();
$endCutoff = $date->getNowDayEndDiff();

View File

@ -13,6 +13,8 @@ var currentElem;
var serverUpdateInterval = 5000;
var uiUpdateInterval = 200;
var timezoneOffset = 0;
//set to "development" if we are developing :). Useful to disable alerts
//when entering production mode.
var APPLICATION_ENV = "";
@ -169,7 +171,7 @@ function updatePlaybar(){
}
/* Column 2 update */
$('#time').text(convertDateToHHMMSS(estimatedSchedulePosixTime));
$('#time').text(convertDateToHHMMSS(estimatedSchedulePosixTime + timezoneOffset));
}
function calcAdditionalData(currentItem){
@ -209,7 +211,7 @@ function parseItems(obj){
calcAdditionalShowData(obj.nextShow);
var schedulePosixTime = convertDateToPosixTime(obj.schedulerTime);
schedulePosixTime += parseInt(obj.timezoneOffset)*1000;
timezoneOffset = parseInt(obj.timezoneOffset)*1000;
var date = new Date();
localRemoteTimeOffset = date.getTime() - schedulePosixTime;
}