CC-5594 : Remove all date_default_timezone_get()

using the user selected timezone in the form to calculate duration.
This commit is contained in:
Naomi 2013-12-05 15:12:01 -05:00
parent c732b44903
commit 39063aaadb
3 changed files with 22 additions and 11 deletions

View file

@ -630,9 +630,12 @@ class ScheduleController extends Zend_Controller_Action
public function calculateDurationAction()
{
$start = $this->_getParam('startTime');
$end = $this->_getParam('endTime');
$timezone = $this->_getParam('timezone');
$service_showForm = new Application_Service_ShowFormService();
$result = $service_showForm->calculateDuration($this->_getParam('startTime'),
$this->_getParam('endTime'));
$result = $service_showForm->calculateDuration($start, $end, $timezone);
echo Zend_Json::encode($result);
exit();

View file

@ -470,11 +470,13 @@ class Application_Service_ShowFormService
}
}
public function calculateDuration($start, $end)
public function calculateDuration($start, $end, $timezone)
{
try {
$startDateTime = new DateTime($start);
$endDateTime = new DateTime($end);
$tz = new DateTimeZone($timezone);
$startDateTime = new DateTime($start, $tz);
$endDateTime = new DateTime($end, $tz);
$duration = $startDateTime->diff($endDateTime);
@ -490,6 +492,7 @@ class Application_Service_ShowFormService
return $duration->format('%r%Hh %Im');
}
} catch (Exception $e) {
Logging::info($e->getMessage());
return "Invalid Date";
}
}