Skip to content

Commit

Permalink
CC-5727 : History search range using incorrect timezone offset (also …
Browse files Browse the repository at this point in the history
…Nowplaying)

sending the timestamp string back for nowplaying as well.
added error class to history page if end is < start.
  • Loading branch information
naomiaro committed Mar 10, 2014
1 parent 1854d76 commit 8d2926a
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 66 deletions.
75 changes: 54 additions & 21 deletions airtime_mvc/application/controllers/ShowbuilderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,24 +235,61 @@ public function builderDialogAction()

$this->view->dialog = $this->view->render('showbuilder/builderDialog.phtml');
}

private function getStartEnd()
{
$request = $this->getRequest();

$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$utcTimezone = new DateTimeZone("UTC");
$utcNow = new DateTime("now", $utcTimezone);

$start = $request->getParam("start");
$end = $request->getParam("end");

if (empty($start) || empty($end)) {
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
else {

try {
$startsDT = new DateTime($start, $userTimezone);
$startsDT->setTimezone($utcTimezone);

$endsDT = new DateTime($end, $userTimezone);
$endsDT->setTimezone($utcTimezone);

if ($startsDT > $endsDT) {
throw new Exception("start greater than end");
}
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());

$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}

}

return array($startsDT, $endsDT);
}

public function checkBuilderFeedAction()
{
$request = $this->getRequest();
$current_time = time();

$starts_epoch = $request->getParam("start", $current_time);
//default ends is 24 hours after starts.
$ends_epoch = $request->getParam("end", $current_time + (60*60*24));
$request = $this->getRequest();
$show_filter = intval($request->getParam("showFilter", 0));
$my_shows = intval($request->getParam("myShows", 0));
$timestamp = intval($request->getParam("timestamp", -1));
$instances = $request->getParam("instances", array());
$my_shows = intval($request->getParam("myShows", 0));
$timestamp = intval($request->getParam("timestamp", -1));
$instances = $request->getParam("instances", array());

$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
list($startsDT, $endsDT) = $this->getStartEnd();

$opts = array("myShows" => $my_shows, "showFilter" => $show_filter);
$opts = array("myShows" => $my_shows, "showFilter" => $show_filter);
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);

//only send the schedule back if updates have been made.
Expand All @@ -263,18 +300,14 @@ public function checkBuilderFeedAction()

public function builderFeedAction()
{
$request = $this->getRequest();
$current_time = time();

$starts_epoch = $request->getParam("start", $current_time);
//default ends is 24 hours after starts.
$ends_epoch = $request->getParam("end", $current_time + (60*60*24));
$current_time = time();

$request = $this->getRequest();
$show_filter = intval($request->getParam("showFilter", 0));
$show_instance_filter = intval($request->getParam("showInstanceFilter", 0));
$my_shows = intval($request->getParam("myShows", 0));
$my_shows = intval($request->getParam("myShows", 0));

$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
list($startsDT, $endsDT) = $this->getStartEnd();

$opts = array("myShows" => $my_shows,
"showFilter" => $show_filter,
Expand Down
4 changes: 4 additions & 0 deletions airtime_mvc/public/css/history_styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,7 @@
#history_content .ui-tabs .ui-tabs-panel {
padding-top: 10px;
}

div.his-timerange input.error {
background-color: rgba(255,0,0,0.2);
}
79 changes: 45 additions & 34 deletions airtime_mvc/public/js/airtime/playouthistory/historytable.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ var AIRTIME = (function(AIRTIME) {
oTableShow,
inShowsTab = false;

function validateTimeRange() {
var oRange,
inputs = $('.his-timerange > input'),
start, end;

oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId);

start = oRange.start;
end = oRange.end;

if (end >= start) {
inputs.removeClass('error');
}
else {
inputs.addClass('error');
}

return {
start: start,
end: end,
isValid: end >= start
};
}

function getSelectedLogItems() {
var items = Object.keys(selectedLogItems);

Expand Down Expand Up @@ -545,7 +569,8 @@ var AIRTIME = (function(AIRTIME) {
dayNamesMin: i18n_days_short,
onSelect: function(sDate, oDatePicker) {
$(this).datepicker( "setDate", sDate );
}
},
onClose: validateTimeRange
};

oBaseTimePickerSettings = {
Expand All @@ -555,13 +580,25 @@ var AIRTIME = (function(AIRTIME) {
showLeadingZero: false,
defaultTime: '0:00',
hourText: $.i18n._("Hour"),
minuteText: $.i18n._("Minute")
minuteText: $.i18n._("Minute"),
onClose: validateTimeRange
};

$historyContentDiv.find(dateStartId).datepicker(oBaseDatePickerSettings);
$historyContentDiv.find(timeStartId).timepicker(oBaseTimePickerSettings);
$historyContentDiv.find(dateEndId).datepicker(oBaseDatePickerSettings);
$historyContentDiv.find(timeEndId).timepicker(oBaseTimePickerSettings);
$historyContentDiv.find(dateStartId)
.datepicker(oBaseDatePickerSettings)
.blur(validateTimeRange);

$historyContentDiv.find(timeStartId)
.timepicker(oBaseTimePickerSettings)
.blur(validateTimeRange);

$historyContentDiv.find(dateEndId)
.datepicker(oBaseDatePickerSettings)
.blur(validateTimeRange);

$historyContentDiv.find(timeEndId)
.timepicker(oBaseTimePickerSettings)
.blur(validateTimeRange);

$historyContentDiv.on("click", "#his_create", function(e) {
var url = baseUrl+"playouthistory/edit-list-item/format/json" ;
Expand Down Expand Up @@ -711,35 +748,9 @@ var AIRTIME = (function(AIRTIME) {
});
});

function getStartEnd() {
var start,
end,
time;

start = $(dateStartId).val();
start = start === "" ? null : start;

time = $(timeStartId).val();
time = time === "" ? "00:00" : time;

if (start) {
start = start + " " + time;
}

end = $(dateEndId).val();
end = end === "" ? null : end;

time = $(timeEndId).val();
time = time === "" ? "00:00" : time;

if (end) {
end = end + " " + time;
}
function getStartEnd() {

return {
start: start,
end: end
};
return AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId);
}

$historyContentDiv.find("#his_submit").click(function(ev){
Expand Down
3 changes: 2 additions & 1 deletion airtime_mvc/public/js/airtime/showbuilder/main_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ AIRTIME = (function(AIRTIME) {
showLeadingZero: false,
defaultTime: '0:00',
hourText: $.i18n._("Hour"),
minuteText: $.i18n._("Minute")
minuteText: $.i18n._("Minute"),
onClose: validateTimeRange
};

function setWidgetSize() {
Expand Down
34 changes: 24 additions & 10 deletions airtime_mvc/public/js/airtime/utilities/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,34 @@ var AIRTIME = (function(AIRTIME){
*
* @return Object {"start", "end", "range"}
*/
mod.fnGetScheduleRange = function(dateStart, timeStart, dateEnd, timeEnd) {
var iStart,
iEnd,
iRange;
mod.fnGetScheduleRange = function(dateStartId, timeStartId, dateEndId, timeEndId) {
var start,
end,
time;

iStart = AIRTIME.utilities.fnGetTimestamp(dateStart, timeStart);
iEnd = AIRTIME.utilities.fnGetTimestamp(dateEnd, timeEnd);
start = $(dateStartId).val();
start = start === "" ? null : start;

iRange = iEnd - iStart;
time = $(timeStartId).val();
time = time === "" ? "00:00" : time;

if (start) {
start = start + " " + time;
}

end = $(dateEndId).val();
end = end === "" ? null : end;

time = $(timeEndId).val();
time = time === "" ? "00:00" : time;

if (end) {
end = end + " " + time;
}

return {
start: iStart,
end: iEnd,
range: iRange
start: start,
end: end
};
};

Expand Down

0 comments on commit 8d2926a

Please sign in to comment.