From 5f3199b4bb197cf8177fca8456e85c0abc6d3aa9 Mon Sep 17 00:00:00 2001 From: Naomi Date: Mon, 10 Mar 2014 17:39:17 -0400 Subject: [PATCH] CC-5727 : History search range using incorrect timezone offset --- .../controllers/PlayouthistoryController.php | 84 +++++++++++++------ .../js/airtime/playouthistory/historytable.js | 52 +++++++++--- 2 files changed, 99 insertions(+), 37 deletions(-) diff --git a/airtime_mvc/application/controllers/PlayouthistoryController.php b/airtime_mvc/application/controllers/PlayouthistoryController.php index cbd15517f..a2352f4b7 100644 --- a/airtime_mvc/application/controllers/PlayouthistoryController.php +++ b/airtime_mvc/application/controllers/PlayouthistoryController.php @@ -82,20 +82,58 @@ class PlayouthistoryController extends Zend_Controller_Action $user = Application_Model_User::getCurrentUser(); $this->view->userType = $user->getType(); } + + 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 fileHistoryFeedAction() { try { $request = $this->getRequest(); - $current_time = time(); - - $params = $request->getParams(); - - $starts_epoch = $request->getParam("start", $current_time - (60*60*24)); - $ends_epoch = $request->getParam("end", $current_time); - - $startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); - $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); + $params = $request->getParams(); + $instance = $request->getParam("instance_id", null); + + list($startsDT, $endsDT) = $this->getStartEnd(); $historyService = new Application_Service_HistoryService(); $r = $historyService->getFileSummaryData($startsDT, $endsDT, $params); @@ -114,18 +152,12 @@ class PlayouthistoryController extends Zend_Controller_Action public function itemHistoryFeedAction() { try { - $request = $this->getRequest(); - $current_time = time(); - - $params = $request->getParams(); - - $starts_epoch = $request->getParam("start", $current_time - (60*60*24)); - $ends_epoch = $request->getParam("end", $current_time); - $instance = $request->getParam("instance_id", null); - - $startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); - $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); - + $request = $this->getRequest(); + $params = $request->getParams(); + $instance = $request->getParam("instance_id", null); + + list($startsDT, $endsDT) = $this->getStartEnd(); + $historyService = new Application_Service_HistoryService(); $r = $historyService->getPlayedItemData($startsDT, $endsDT, $params, $instance); @@ -144,12 +176,10 @@ class PlayouthistoryController extends Zend_Controller_Action { try { $request = $this->getRequest(); - $current_time = time(); - $starts_epoch = $request->getParam("start", $current_time - (60*60*24)); - $ends_epoch = $request->getParam("end", $current_time); - - $startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); - $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); + $params = $request->getParams(); + $instance = $request->getParam("instance_id", null); + + list($startsDT, $endsDT) = $this->getStartEnd(); $historyService = new Application_Service_HistoryService(); $shows = $historyService->getShowList($startsDT, $endsDT); diff --git a/airtime_mvc/public/js/airtime/playouthistory/historytable.js b/airtime_mvc/public/js/airtime/playouthistory/historytable.js index 056de9a30..b5a43e38c 100644 --- a/airtime_mvc/public/js/airtime/playouthistory/historytable.js +++ b/airtime_mvc/public/js/airtime/playouthistory/historytable.js @@ -401,13 +401,12 @@ var AIRTIME = (function(AIRTIME) { return oTable; } - function showSummaryList() { + function showSummaryList(start, end) { var url = baseUrl+"playouthistory/show-history-feed", - oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId), data = { format: "json", - start: oRange.start, - end: oRange.end + start: start, + end: end }; $.post(url, data, function(json) { @@ -460,7 +459,9 @@ var AIRTIME = (function(AIRTIME) { }, always: function() { inShowsTab = true; - showSummaryList(); + + var info = getStartEnd(); + showSummaryList(info.start, info.end); emptySelectedLogItems(); } } @@ -710,18 +711,49 @@ 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; + } + + return { + start: start, + end: end + }; + } + $historyContentDiv.find("#his_submit").click(function(ev){ var fn, - oRange; + info; - oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId); + info = getStartEnd(); fn = fnServerData; - fn.start = oRange.start; - fn.end = oRange.end; + fn.start = info.start; + fn.end = info.end; if (inShowsTab) { - showSummaryList(); + showSummaryList(info.start, info.end); } else { redrawTables();