CC-5594 : Remove all date_default_timezone_get()

updating move show code to work with the user's timezone.
unified method signature for updateScheduleStartTime to always use the $diff param.
This commit is contained in:
Naomi 2013-12-06 12:33:36 -05:00
parent 061897a58b
commit 7e9ca3e950
3 changed files with 20 additions and 31 deletions

View File

@ -213,7 +213,7 @@ class Application_Common_DateHelper
$dateTime = new DateTime($p_dateString, new DateTimeZone($timezone)); $dateTime = new DateTime($p_dateString, new DateTimeZone($timezone));
} }
else { else {
$dateTime = new DateTime($p_dateString, new DateTimeZone(date_default_timezone_get())); $dateTime = new DateTime($p_dateString, new DateTimeZone(Application_Model_Preference::GetTimezone()));
} }
$dateTime->setTimezone(new DateTimeZone("UTC")); $dateTime->setTimezone(new DateTimeZone("UTC"));

View File

@ -244,8 +244,8 @@ class Application_Service_CalendarService
$today_timestamp = time(); $today_timestamp = time();
$startsDateTime = new DateTime($this->ccShowInstance->getDbStarts(), new DateTimeZone("UTC")); $startsDateTime = $this->ccShowInstance->getDbStarts(null);
$endsDateTime = new DateTime($this->ccShowInstance->getDbEnds(), new DateTimeZone("UTC")); $endsDateTime = $this->ccShowInstance->getDbEnds(null);
if ($today_timestamp > $startsDateTime->getTimestamp()) { if ($today_timestamp > $startsDateTime->getTimestamp()) {
throw new Exception(_("Can't move a past show")); throw new Exception(_("Can't move a past show"));
@ -315,13 +315,16 @@ class Application_Service_CalendarService
$con = Propel::getConnection(); $con = Propel::getConnection();
$con->beginTransaction(); $con->beginTransaction();
//new starts,ends are in UTC
list($newStartsDateTime, $newEndsDateTime) = $this->validateShowMove( list($newStartsDateTime, $newEndsDateTime) = $this->validateShowMove(
$deltaDay, $deltaMin); $deltaDay, $deltaMin);
$oldStartDateTime = $this->ccShowInstance->getDbStarts(null);
$this->ccShowInstance $this->ccShowInstance
->setDbStarts($newStartsDateTime) ->setDbStarts($newStartsDateTime)
->setDbEnds($newEndsDateTime) ->setDbEnds($newEndsDateTime)
->save(); ->save($con);
if (!$this->ccShowInstance->getCcShow()->isRebroadcast()) { if (!$this->ccShowInstance->getCcShow()->isRebroadcast()) {
//we can get the first show day because we know the show is //we can get the first show day because we know the show is
@ -331,11 +334,13 @@ class Application_Service_CalendarService
$ccShowDay $ccShowDay
->setDbFirstShow($newStartsDateTime->setTimezone($showTimezone)->format("Y-m-d")) ->setDbFirstShow($newStartsDateTime->setTimezone($showTimezone)->format("Y-m-d"))
->setDbStartTime($newStartsDateTime->format("H:i")) ->setDbStartTime($newStartsDateTime->format("H:i"))
->save(); ->save($con);
} }
$diff = $newStartsDateTime->getTimestamp() - $oldStartDateTime->getTimestamp();
Application_Service_SchedulerService::updateScheduleStartTime( Application_Service_SchedulerService::updateScheduleStartTime(
array($this->ccShowInstance->getDbId()), null, $newStartsDateTime); array($this->ccShowInstance->getDbId()), $diff);
$con->commit(); $con->commit();
Application_Model_RabbitMq::PushSchedule(); Application_Model_RabbitMq::PushSchedule();

View File

@ -44,47 +44,31 @@ class Application_Service_SchedulerService
* Applies the show start difference to any scheduled items * Applies the show start difference to any scheduled items
* *
* @param $instanceIds * @param $instanceIds
* @param $diff * @param $diff (integer, difference between unix epoch in seconds)
* @param $newStart
*/ */
public static function updateScheduleStartTime($instanceIds, $diff=null, $newStart=null) public static function updateScheduleStartTime($instanceIds, $diff)
{ {
$con = Propel::getConnection(); $con = Propel::getConnection();
if (count($instanceIds) > 0) { if (count($instanceIds) > 0) {
$showIdList = implode(",", $instanceIds); $showIdList = implode(",", $instanceIds);
if (is_null($diff)) {
$ccSchedule = CcScheduleQuery::create()
->filterByDbInstanceId($instanceIds, Criteria::IN)
->orderByDbStarts()
->limit(1)
->findOne();
if (!is_null($ccSchedule)) {
$scheduleStartsEpoch = strtotime($ccSchedule->getDbStarts());
$showStartsEpoch = strtotime($newStart->format("Y-m-d H:i:s"));
$diff = $showStartsEpoch - $scheduleStartsEpoch;
}
}
$ccSchedules = CcScheduleQuery::create() $ccSchedules = CcScheduleQuery::create()
->filterByDbInstanceId($instanceIds, Criteria::IN) ->filterByDbInstanceId($instanceIds, Criteria::IN)
->find(); ->find($con);
$interval = new DateInterval("PT".abs($diff)."S"); $interval = new DateInterval("PT".abs($diff)."S");
if ($diff < 0) { if ($diff < 0) {
$interval->invert = 1; $interval->invert = 1;
} }
foreach ($ccSchedules as $ccSchedule) { foreach ($ccSchedules as $ccSchedule) {
$start = new DateTime($ccSchedule->getDbStarts()); $start = $ccSchedule->getDbStarts(null);
$newStart = $start->add($interval); $newStart = $start->add($interval);
$end = new DateTime($ccSchedule->getDbEnds()); $end = $ccSchedule->getDbEnds(null);
$newEnd = $end->add($interval); $newEnd = $end->add($interval);
$ccSchedule $ccSchedule
->setDbStarts($newStart->format("Y-m-d H:i:s")) ->setDbStarts($newStart)
->setDbEnds($newEnd->format("Y-m-d H:i:s")) ->setDbEnds($newEnd)
->save(); ->save($con);
} }
} }
} }