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; return null;
} else { } else {
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"], return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]), "starts"=>$row[0]["starts"],
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"])); "ends"=>$row[0]["ends"]);
} }
} else { } else {
if (count($row) == 0){ if (count($row) == 0){
//last item is a show instance //last item is a show instance
return array("name"=>$showInstance->getName(), return array("name"=>$showInstance->getName(),
"starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()), "starts"=>$showInstance->getShowStart(),
"ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd())); "ends"=>$showInstance->getShowEnd());
} else { } else {
//return the one that started later. //return the one that started later.
if ($row[0]["starts"] >= $showInstance->getShowStart()){ if ($row[0]["starts"] >= $showInstance->getShowStart()){
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"], return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]), "starts"=>$row[0]["starts"],
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"])); "ends"=>$row[0]["ends"]);
} else { } else {
return array("name"=>$showInstance->getName(), return array("name"=>$showInstance->getName(),
"starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()), "starts"=>$showInstance->getShowStart(),
"ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd())); "ends"=>$showInstance->getShowEnd());
} }
} }
} }
@ -63,21 +63,21 @@ class Application_Model_Dashboard
* in the future. * in the future.
*/ */
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"], return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]), "starts"=>$row[0]["starts"],
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"])); "ends"=>$row[0]["ends"]);
} }
} else { } else {
if (count($row) == 0){ if (count($row) == 0){
//last item is a show instance //last item is a show instance
return array("name"=>$showInstance->getName(), return array("name"=>$showInstance->getName(),
"starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()), "starts"=>$showInstance->getShowStart(),
"ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd()), "ends"=>$showInstance->getShowEnd(),
"media_item_played"=>false, "media_item_played"=>false,
"record"=>$showInstance->isRecorded()); "record"=>$showInstance->isRecorded());
} else { } else {
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"], return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]), "starts"=>$row[0]["starts"],
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"]), "ends"=>$row[0]["ends"],
"media_item_played"=>$row[0]["media_item_played"], "media_item_played"=>$row[0]["media_item_played"],
"record"=>0); "record"=>0);
} }
@ -98,26 +98,26 @@ class Application_Model_Dashboard
return null; return null;
} else { } else {
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"], return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]), "starts"=>$row[0]["starts"],
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"])); "ends"=>$row[0]["ends"]);
} }
} else { } else {
if (count($row) == 0){ if (count($row) == 0){
//last item is a show instance //last item is a show instance
return array("name"=>$showInstance->getName(), return array("name"=>$showInstance->getName(),
"starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()), "starts"=>$showInstance->getShowStart(),
"ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd())); "ends"=>$showInstance->getShowEnd());
} else { } else {
//return the one that starts sooner. //return the one that starts sooner.
if ($row[0]["starts"] <= $showInstance->getShowStart()){ if ($row[0]["starts"] <= $showInstance->getShowStart()){
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"], return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]), "starts"=>$row[0]["starts"],
"ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"])); "ends"=>$row[0]["ends"]);
} else { } else {
return array("name"=>$showInstance->getName(), return array("name"=>$showInstance->getName(),
"starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()), "starts"=>$showInstance->getShowStart(),
"ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd())); "ends"=>$showInstance->getShowEnd());
} }
} }
} }

View File

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

View File

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

View File

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