cc-2683: not using utc time

-context menu showing options display correctly
-edit show fills in correctly
-Now Playing view shows up correctly
This commit is contained in:
martin 2011-08-15 16:40:24 -04:00
parent 03f8163764
commit 41fd5f2543
7 changed files with 109 additions and 57 deletions

View File

@ -176,15 +176,18 @@ class ScheduleController extends Zend_Controller_Action
public function makeContextMenuAction() public function makeContextMenuAction()
{ {
$id = $this->_getParam('id'); $id = $this->_getParam('id');
$today_timestamp = date("Y-m-d H:i:s"); $epochNow = time();
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new User($userInfo->id); $user = new User($userInfo->id);
$show = new ShowInstance($id); $show = new ShowInstance($id);
$params = '/format/json/id/#id#'; $params = '/format/json/id/#id#';
if (strtotime($today_timestamp) < strtotime($show->getShowStart())) { $showStartDateHelper = DateHelper::ConvertToLocalDateTime($show->getShowStart());
$showEndDateHelper = DateHelper::ConvertToLocalDateTime($show->getShowEnd());
if ($epochNow < $showStartDateHelper->getTimestamp()) {
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId()) && !$show->isRecorded() && !$show->isRebroadcast()) { if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId()) && !$show->isRecorded() && !$show->isRebroadcast()) {
@ -202,7 +205,7 @@ class ScheduleController extends Zend_Controller_Action
'callback' => 'window["buildContentDialog"]'), 'title' => 'Show Content'); 'callback' => 'window["buildContentDialog"]'), 'title' => 'Show Content');
} }
if (strtotime($show->getShowEnd()) <= strtotime($today_timestamp) if ($showEndDateHelper->getTimestamp() <= $epochNow
&& is_null($show->getSoundCloudFileId()) && is_null($show->getSoundCloudFileId())
&& $show->isRecorded() && $show->isRecorded()
&& Application_Model_Preference::GetDoSoundCloudUpload()) { && Application_Model_Preference::GetDoSoundCloudUpload()) {
@ -212,15 +215,15 @@ class ScheduleController extends Zend_Controller_Action
} }
if (strtotime($show->getShowStart()) <= strtotime($today_timestamp) && if ($showStartDateHelper->getTimestamp() <= $epochNow &&
strtotime($today_timestamp) < strtotime($show->getShowEnd()) && $epochNow < $showEndDateHelper->getTimestamp() &&
$user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
$menu[] = array('action' => array('type' => 'fn', $menu[] = array('action' => array('type' => 'fn',
'callback' => "window['confirmCancelShow']($id)"), 'callback' => "window['confirmCancelShow']($id)"),
'title' => 'Cancel Current Show'); 'title' => 'Cancel Current Show');
} }
if (strtotime($today_timestamp) < strtotime($show->getShowStart())) { if ($epochNow < $showStartDateHelper->getTimestamp()) {
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
@ -425,11 +428,17 @@ class ScheduleController extends Zend_Controller_Action
'add_show_url' => $show->getUrl(), 'add_show_url' => $show->getUrl(),
'add_show_genre' => $show->getGenre(), 'add_show_genre' => $show->getGenre(),
'add_show_description' => $show->getDescription())); 'add_show_description' => $show->getDescription()));
$startsDateTime = new DateTime($showInstance->getShowStart(), new DateTimeZone("UTC"));
$endsDateTime = new DateTime($showInstance->getShowEnd(), new DateTimeZone("UTC"));
$startsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
$endsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
$formWhen->populate(array('add_show_start_date' => $show->getStartDate(), $formWhen->populate(array('add_show_start_date' => $startsDateTime->format("Y-m-d"),
'add_show_start_time' => DateHelper::removeSecondsFromTime($show->getStartTime()), 'add_show_start_time' => $startsDateTime->format("H:i"),
'add_show_end_date_no_repeat' => $show->getEndDate(), 'add_show_end_date_no_repeat' => $endsDateTime->format("Y-m-d"),
'add_show_end_time' => DateHelper::removeSecondsFromTime($show->getEndTime()), 'add_show_end_time' => $endsDateTime->format("H:i"),
'add_show_duration' => $show->getDuration(true), 'add_show_duration' => $show->getDuration(true),
'add_show_repeats' => $show->isRepeating() ? 1 : 0)); 'add_show_repeats' => $show->isRepeating() ? 1 : 0));

View File

@ -16,4 +16,9 @@ class Logging {
public static function setLogPath($path){ public static function setLogPath($path){
self::$_path = $path; self::$_path = $path;
} }
public static function log($p_msg){
$logger = self::getLogger();
$logger->info($p_msg);
}
} }

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"=>$row[0]["starts"], "starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>$row[0]["ends"]); "ends"=>DateHelper::ConvertToLocalDateTimeString($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"=>$showInstance->getShowStart(), "starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()),
"ends"=>$showInstance->getShowEnd()); "ends"=>DateHelper::ConvertToLocalDateTimeString($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"=>$row[0]["starts"], "starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>$row[0]["ends"]); "ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"]));
} else { } else {
return array("name"=>$showInstance->getName(), return array("name"=>$showInstance->getName(),
"starts"=>$showInstance->getShowStart(), "starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()),
"ends"=>$showInstance->getShowEnd()); "ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd()));
} }
} }
} }
@ -49,7 +49,7 @@ class Application_Model_Dashboard
//name. Else return the last item from the schedule. //name. Else return the last item from the schedule.
$row = array(); $row = array();
$showInstance = ShowInstance::GetCurrentShowInstance($p_timeNow); $showInstance = ShowInstance::GetCurrentShowInstance($p_timeNow);
if (!is_null($showInstance)){ if (!is_null($showInstance)){
$instanceId = $showInstance->getShowInstanceId(); $instanceId = $showInstance->getShowInstanceId();
$row = Schedule::GetCurrentScheduleItem($p_timeNow, $instanceId); $row = Schedule::GetCurrentScheduleItem($p_timeNow, $instanceId);
@ -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"=>$row[0]["starts"], "starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>$row[0]["ends"]); "ends"=>DateHelper::ConvertToLocalDateTimeString($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"=>$showInstance->getShowStart(), "starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()),
"ends"=>$showInstance->getShowEnd(), "ends"=>DateHelper::ConvertToLocalDateTimeString($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"=>$row[0]["starts"], "starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>$row[0]["ends"], "ends"=>DateHelper::ConvertToLocalDateTimeString($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"=>$row[0]["starts"], "starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>$row[0]["ends"]); "ends"=>DateHelper::ConvertToLocalDateTimeString($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"=>$showInstance->getShowStart(), "starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()),
"ends"=>$showInstance->getShowEnd()); "ends"=>DateHelper::ConvertToLocalDateTimeString($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"=>$row[0]["starts"], "starts"=>DateHelper::ConvertToLocalDateTimeString($row[0]["starts"]),
"ends"=>$row[0]["ends"]); "ends"=>DateHelper::ConvertToLocalDateTimeString($row[0]["ends"]));
} else { } else {
return array("name"=>$showInstance->getName(), return array("name"=>$showInstance->getName(),
"starts"=>$showInstance->getShowStart(), "starts"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowStart()),
"ends"=>$showInstance->getShowEnd()); "ends"=>DateHelper::ConvertToLocalDateTimeString($showInstance->getShowEnd()));
} }
} }
} }

View File

@ -17,6 +17,18 @@ class DateHelper
{ {
return date("Y-m-d H:i:s", $this->_timestamp); return date("Y-m-d H:i:s", $this->_timestamp);
} }
/**
* Get time of object construction in the format
* YYYY-MM-DD HH:mm:ss
*/
function getUtcTimestamp()
{
$dateTime = new DateTime("@".$this->_timestamp);
$dateTime->setTimezone(new DateTimeZone("UTC"));
return $dateTime->format("Y-m-d H:i:s");
}
/** /**
* Get date of object construction in the format * Get date of object construction in the format
@ -157,5 +169,19 @@ class DateHelper
return $totalSeconds; return $totalSeconds;
} }
public static function ConvertToLocalDateTime($p_dateString){
$dateTime = new DateTime($p_dateString, new DateTimeZone("UTC"));
$dateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
return $dateTime;
}
public static function ConvertToLocalDateTimeString($p_dateString, $format="Y-m-d H:i:s"){
$dateTime = new DateTime($p_dateString, new DateTimeZone("UTC"));
$dateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
return $dateTime->format($format);
}
} }

View File

@ -3,21 +3,31 @@
class Application_Model_Nowplaying class Application_Model_Nowplaying
{ {
public static function CreateHeaderRow($p_showName, $p_showStart, $p_showEnd){ private static function CreateHeaderRow($p_showName, $p_showStart, $p_showEnd){
return array("h", "", $p_showStart, $p_showEnd, $p_showName, "", "", "", "", "", ""); return array("h", "", $p_showStart, $p_showEnd, $p_showName, "", "", "", "", "", "");
} }
public static function CreateDatatableRows($p_dbRows){ private static function CreateDatatableRows($p_dbRows){
$dataTablesRows = array(); $dataTablesRows = array();
$date = new DateHelper; $epochNow = time();
$timeNow = $date->getTimestamp();
foreach ($p_dbRows as $dbRow){ foreach ($p_dbRows as $dbRow){
$showStartDateTime = DateHelper::ConvertToLocalDateTime($dbRow['show_starts']);
$showEndDateTime = DateHelper::ConvertToLocalDateTime($dbRow['show_ends']);
$itemStartDateTime = DateHelper::ConvertToLocalDateTime($dbRow['item_starts']);
$itemEndDateTime = DateHelper::ConvertToLocalDateTime($dbRow['item_ends']);
$showStarts = $showStartDateTime->format("Y-m-d H:i:s");
$showEnds = $showEndDateTime->format("Y-m-d H:i:s");
$itemStarts = $itemStartDateTime->format("Y-m-d H:i:s");
$itemEnds = $itemEndDateTime->format("Y-m-d H:i:s");
$status = ($dbRow['show_ends'] < $dbRow['item_ends']) ? "x" : ""; $status = ($dbRow['show_ends'] < $dbRow['item_ends']) ? "x" : "";
$type = "a"; $type = "a";
$type .= ($dbRow['item_ends'] > $timeNow && $dbRow['item_starts'] <= $timeNow) ? "c" : ""; $type .= ($itemEndDateTime->getTimestamp() > $epochNow && $itemStartDateTime->getTimestamp() <= $epochNow) ? "c" : "";
// remove millisecond from the time format // remove millisecond from the time format
$itemStart = explode('.', $dbRow['item_starts']); $itemStart = explode('.', $dbRow['item_starts']);
@ -25,20 +35,20 @@ class Application_Model_Nowplaying
//format duration //format duration
$duration = explode('.', $dbRow['clip_length']); $duration = explode('.', $dbRow['clip_length']);
$formated = Application_Model_Nowplaying::FormatDuration($duration[0]); $formatted = self::FormatDuration($duration[0]);
$dataTablesRows[] = array($type, $dbRow['show_starts'], $itemStart[0], $itemEnd[0], $dataTablesRows[] = array($type, $showStarts, $itemStarts, $itemEnds,
$formated, $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'], $formatted, $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'],
$dbRow['playlist_name'], $dbRow['show_name'], $status); $dbRow['playlist_name'], $dbRow['show_name'], $status);
} }
return $dataTablesRows; return $dataTablesRows;
} }
public static function CreateGapRow($p_gapTime){ private static function CreateGapRow($p_gapTime){
return array("g", "", "", "", $p_gapTime, "", "", "", "", "", ""); return array("g", "", "", "", $p_gapTime, "", "", "", "", "", "");
} }
public static function CreateRecordingRow($p_showInstance){ private static function CreateRecordingRow($p_showInstance){
return array("r", "", "", "", $p_showInstance->getName(), "", "", "", "", "", ""); return array("r", "", "", "", $p_showInstance->getName(), "", "", "", "", "", "");
} }
@ -71,21 +81,24 @@ class Application_Model_Nowplaying
$showId = $si->getShowId(); $showId = $si->getShowId();
$show = new Show($showId); $show = new Show($showId);
$showStartDateTime = DateHelper::ConvertToLocalDateTime($si->getShowStart());
$showEndDateTime = DateHelper::ConvertToLocalDateTime($si->getShowEnd());
//append show header row //append show header row
$data[] = Application_Model_Nowplaying::CreateHeaderRow($show->getName(), $si->getShowStart(), $si->getShowEnd()); $data[] = self::CreateHeaderRow($show->getName(), $showStartDateTime->format("Y-m-d H:i:s"), $showEndDateTime->format("Y-m-d H:i:s"));
$scheduledItems = $si->getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff); $scheduledItems = $si->getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff);
$dataTablesRows = Application_Model_Nowplaying::CreateDatatableRows($scheduledItems); $dataTablesRows = self::CreateDatatableRows($scheduledItems);
//append show audio item rows //append show audio item rows
$data = array_merge($data, $dataTablesRows); $data = array_merge($data, $dataTablesRows);
//append show gap time row //append show gap time row
$gapTime = Application_Model_Nowplaying::FormatDuration($si->getShowEndGapTime(), true); $gapTime = self::FormatDuration($si->getShowEndGapTime(), true);
if ($si->isRecorded()) if ($si->isRecorded())
$data[] = Application_Model_Nowplaying::CreateRecordingRow($si); $data[] = self::CreateRecordingRow($si);
else if ($gapTime > 0) else if ($gapTime > 0)
$data[] = Application_Model_Nowplaying::CreateGapRow($gapTime); $data[] = self::CreateGapRow($gapTime);
} }
return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data); return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data);
@ -102,7 +115,7 @@ class Application_Model_Nowplaying
* default $time format should be in format of 00:00:00 * default $time format should be in format of 00:00:00
* if $inSecond = true, then $time should be in seconds * if $inSecond = true, then $time should be in seconds
*/ */
public static function FormatDuration($time, $inSecond=false){ private static function FormatDuration($time, $inSecond=false){
if($inSecond == false){ if($inSecond == false){
$duration = explode(':', $time); $duration = explode(':', $time);
}else{ }else{

View File

@ -364,12 +364,9 @@ class Schedule {
global $CC_CONFIG; global $CC_CONFIG;
$date = new DateHelper; $date = new DateHelper;
$timeNow = $date->getTimestamp(); $timeNow = $date->getUtcTimestamp();
return array("env"=>APPLICATION_ENV, return array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"), "schedulerTime"=>$timeNow,
//"previous"=>Schedule::GetScheduledItemData($timeNow, -1, $prev, "24 hours"),
//"current"=>Schedule::GetScheduledItemData($timeNow, 0),
//"next"=>Schedule::GetScheduledItemData($timeNow, 1, $next, "48 hours"),
"previous"=>Application_Model_Dashboard::GetPreviousItem($timeNow), "previous"=>Application_Model_Dashboard::GetPreviousItem($timeNow),
"current"=>Application_Model_Dashboard::GetCurrentItem($timeNow), "current"=>Application_Model_Dashboard::GetCurrentItem($timeNow),
"next"=>Application_Model_Dashboard::GetNextItem($timeNow), "next"=>Application_Model_Dashboard::GetNextItem($timeNow),

View File

@ -47,7 +47,7 @@ def getDateTimeObj(time):
date = timeinfo[0].split("-") date = timeinfo[0].split("-")
time = timeinfo[1].split(":") time = timeinfo[1].split(":")
return datetime.datetime(int(date[0]), int(date[1]), int(date[2]), int(time[0]), int(time[1]), int(time[2])) return datetime.datetime(int(date[0]), int(date[1]), int(date[2]), int(time[0]), int(time[1]), int(time[2]), None)
class ShowRecorder(Thread): class ShowRecorder(Thread):
@ -208,6 +208,8 @@ class CommandListener(Thread):
self.logger.info("Parsing show schedules...") self.logger.info("Parsing show schedules...")
self.shows_to_record = {} self.shows_to_record = {}
for show in shows: for show in shows:
print show
show_starts = getDateTimeObj(show[u'starts']) show_starts = getDateTimeObj(show[u'starts'])
show_end = getDateTimeObj(show[u'ends']) show_end = getDateTimeObj(show[u'ends'])
time_delta = show_end - show_starts time_delta = show_end - show_starts
@ -222,7 +224,7 @@ class CommandListener(Thread):
def get_time_till_next_show(self): def get_time_till_next_show(self):
if len(self.shows_to_record) != 0: if len(self.shows_to_record) != 0:
tnow = datetime.datetime.now() tnow = datetime.datetime.utcnow()
sorted_show_keys = sorted(self.shows_to_record.keys()) sorted_show_keys = sorted(self.shows_to_record.keys())
start_time = sorted_show_keys[0] start_time = sorted_show_keys[0]