cc-2683: not using utc time
-date/time values are converted to UTC before storing in database on show create -cleanup
This commit is contained in:
parent
4f2b2dba6d
commit
6ee3d2f5e0
|
@ -88,18 +88,16 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkReliantFields($formData, $startDateModified) {
|
public function checkReliantFields($formData, $startDateModified) {
|
||||||
|
|
||||||
$valid = true;
|
$valid = true;
|
||||||
|
|
||||||
$now_timestamp = date("Y-m-d H:i:s");
|
$start_time = $formData['add_show_start_date']." ".$formData['add_show_start_time'];
|
||||||
$start_timestamp = $formData['add_show_start_date']." ".$formData['add_show_start_time'];
|
|
||||||
|
//DateTime stores $start_time in the current timezone
|
||||||
$now_epoch = strtotime($now_timestamp);
|
$nowDateTime = new DateTime();
|
||||||
$start_epoch = strtotime($start_timestamp);
|
$showStartDateTime = new DateTime($start_time);
|
||||||
|
|
||||||
|
|
||||||
if ((($formData['add_show_id'] != -1) && $startDateModified) || ($formData['add_show_id'] == -1)){
|
if ((($formData['add_show_id'] != -1) && $startDateModified) || ($formData['add_show_id'] == -1)){
|
||||||
if($start_epoch < $now_epoch) {
|
if($showStartDateTime->getTimestamp() < $nowDateTime->getTimestamp()) {
|
||||||
$this->getElement('add_show_start_time')->setErrors(array('Cannot create show in the past'));
|
$this->getElement('add_show_start_time')->setErrors(array('Cannot create show in the past'));
|
||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
|
@ -118,6 +116,5 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
||||||
|
|
||||||
return $valid;
|
return $valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -724,27 +724,26 @@ class Show {
|
||||||
*/
|
*/
|
||||||
public static function create($data)
|
public static function create($data)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
|
|
||||||
|
$utcStartDateTime = new DateTime($data['add_show_start_date']." ".$data['add_show_start_time']);
|
||||||
$sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$data['add_show_start_date']} {$data['add_show_start_time']}')";
|
$utcStartDateTime->setTimezone(new DateTimeZone('UTC'));
|
||||||
$r = $con->query($sql);
|
|
||||||
$startDow = $r->fetchColumn(0);
|
|
||||||
|
|
||||||
if ($data['add_show_no_end']) {
|
if ($data['add_show_no_end']) {
|
||||||
$endDate = NULL;
|
$endDateTime = NULL;
|
||||||
}
|
}
|
||||||
else if ($data['add_show_repeats']) {
|
else if ($data['add_show_repeats']) {
|
||||||
$sql = "SELECT date '{$data['add_show_end_date']}' + INTERVAL '1 day' ";
|
$endDateTime = new DateTime($data['add_show_end_date']);
|
||||||
$r = $con->query($sql);
|
$endDateTime->setTimezone(new DateTimeZone('UTC'));
|
||||||
$endDate = $r->fetchColumn(0);
|
$endDateTime->add(new DateInterval("P1D"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '1 day' ";
|
$endDateTime = new DateTime($data['add_show_start_date']);
|
||||||
$r = $con->query($sql);
|
$endDateTime->setTimezone(new DateTimeZone('UTC'));
|
||||||
$endDate = $r->fetchColumn(0);
|
$endDateTime->add(new DateInterval("P1D"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//only want the day of the week from the start date.
|
//only want the day of the week from the start date.
|
||||||
|
$startDow = date("w", $utcStartDateTime->getTimestamp());
|
||||||
if (!$data['add_show_repeats']) {
|
if (!$data['add_show_repeats']) {
|
||||||
$data['add_show_day_check'] = array($startDow);
|
$data['add_show_day_check'] = array($startDow);
|
||||||
} else if ($data['add_show_repeats'] && $data['add_show_day_check'] == "") {
|
} else if ($data['add_show_repeats'] && $data['add_show_day_check'] == "") {
|
||||||
|
@ -768,12 +767,12 @@ class Show {
|
||||||
$ccShow->save();
|
$ccShow->save();
|
||||||
|
|
||||||
$showId = $ccShow->getDbId();
|
$showId = $ccShow->getDbId();
|
||||||
$show = new Show($showId);
|
|
||||||
|
|
||||||
$isRecorded = ($data['add_show_record']) ? 1 : 0;
|
$isRecorded = ($data['add_show_record']) ? 1 : 0;
|
||||||
|
|
||||||
if ($data['add_show_id'] != -1){
|
if ($data['add_show_id'] != -1){
|
||||||
$show->deletePossiblyInvalidInstances($data, $endDate, $isRecorded, $repeatType);
|
$show = new Show($showId);
|
||||||
|
$show->deletePossiblyInvalidInstances($data, $endDateTime->format("Y-m-d"), $isRecorded, $repeatType);
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if we are adding or updating a show, and if updating
|
//check if we are adding or updating a show, and if updating
|
||||||
|
@ -785,37 +784,30 @@ class Show {
|
||||||
//don't set day for monthly repeat type, it's invalid.
|
//don't set day for monthly repeat type, it's invalid.
|
||||||
if ($data['add_show_repeats'] && $data['add_show_repeat_type'] == 2){
|
if ($data['add_show_repeats'] && $data['add_show_repeat_type'] == 2){
|
||||||
$showDay = new CcShowDays();
|
$showDay = new CcShowDays();
|
||||||
$showDay->setDbFirstShow($data['add_show_start_date']);
|
$showDay->setDbFirstShow($utcStartDateTime->format("Y-m-d"));
|
||||||
$showDay->setDbLastShow($endDate);
|
$showDay->setDbLastShow($endDateTime->format("Y-m-d"));
|
||||||
$showDay->setDbStartTime($data['add_show_start_time']);
|
$showDay->setDbStartTime($utcStartDateTime->format("H:i:s"));
|
||||||
$showDay->setDbDuration($data['add_show_duration']);
|
$showDay->setDbDuration($data['add_show_duration']);
|
||||||
$showDay->setDbRepeatType($repeatType);
|
$showDay->setDbRepeatType($repeatType);
|
||||||
$showDay->setDbShowId($showId);
|
$showDay->setDbShowId($showId);
|
||||||
$showDay->setDbRecord($isRecorded);
|
$showDay->setDbRecord($isRecorded);
|
||||||
$showDay->save();
|
$showDay->save();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
foreach ($data['add_show_day_check'] as $day) {
|
foreach ($data['add_show_day_check'] as $day) {
|
||||||
if ($startDow !== $day){
|
if ($startDow !== $day){
|
||||||
|
|
||||||
if ($startDow > $day)
|
if ($startDow > $day)
|
||||||
$daysAdd = 6 - $startDow + 1 + $day;
|
$daysAdd = 6 - $startDow + 1 + $day;
|
||||||
else
|
else
|
||||||
$daysAdd = $day - $startDow;
|
$daysAdd = $day - $startDow;
|
||||||
|
|
||||||
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '{$daysAdd} day' ";
|
$utcStartDateTime->add("P".$daysAdd."d");
|
||||||
$r = $con->query($sql);
|
|
||||||
$start = $r->fetchColumn(0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$start = $data['add_show_start_date'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strtotime($start) <= strtotime($endDate) || is_null($endDate)) {
|
if (is_null($endDateTime) || strtotime($utcStartDateTime->format("Y-m-d")) <= $endDateTime->getTimestamp()) {
|
||||||
$showDay = new CcShowDays();
|
$showDay = new CcShowDays();
|
||||||
$showDay->setDbFirstShow($start);
|
$showDay->setDbFirstShow($utcStartDateTime->format("Y-m-d"));
|
||||||
$showDay->setDbLastShow($endDate);
|
$showDay->setDbLastShow($endDateTime->format("Y-m-d"));
|
||||||
$showDay->setDbStartTime($data['add_show_start_time']);
|
$showDay->setDbStartTime($utcStartDateTime->format("H:i:s"));
|
||||||
$showDay->setDbDuration($data['add_show_duration']);
|
$showDay->setDbDuration($data['add_show_duration']);
|
||||||
$showDay->setDbDay($day);
|
$showDay->setDbDay($day);
|
||||||
$showDay->setDbRepeatType($repeatType);
|
$showDay->setDbRepeatType($repeatType);
|
||||||
|
@ -826,15 +818,11 @@ class Show {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$date = new DateHelper();
|
|
||||||
$currentTimestamp = $date->getTimestamp();
|
|
||||||
|
|
||||||
//check if we are adding or updating a show, and if updating
|
//check if we are adding or updating a show, and if updating
|
||||||
//erase all the show's future show_rebroadcast information first.
|
//erase all the show's future show_rebroadcast information first.
|
||||||
if (($data['add_show_id'] != -1) && $data['add_show_rebroadcast']){
|
if (($data['add_show_id'] != -1) && $data['add_show_rebroadcast']){
|
||||||
CcShowRebroadcastQuery::create()
|
CcShowRebroadcastQuery::create()
|
||||||
->filterByDbShowId($data['add_show_id'])
|
->filterByDbShowId($data['add_show_id'])
|
||||||
//->filterByDbStartTime($currentTimestamp, Criteria::GREATER_EQUAL)
|
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
//adding rows to cc_show_rebroadcast
|
//adding rows to cc_show_rebroadcast
|
||||||
|
@ -852,6 +840,7 @@ class Show {
|
||||||
else if ($isRecorded && $data['add_show_rebroadcast'] && ($repeatType == -1)){
|
else if ($isRecorded && $data['add_show_rebroadcast'] && ($repeatType == -1)){
|
||||||
for ($i=1; $i<=10; $i++) {
|
for ($i=1; $i<=10; $i++) {
|
||||||
if ($data['add_show_rebroadcast_date_absolute_'.$i]) {
|
if ($data['add_show_rebroadcast_date_absolute_'.$i]) {
|
||||||
|
$con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
|
||||||
$sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_'.$i]}' - date '{$data['add_show_start_date']}' ";
|
$sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_'.$i]}' - date '{$data['add_show_start_date']}' ";
|
||||||
$r = $con->query($sql);
|
$r = $con->query($sql);
|
||||||
$offset_days = $r->fetchColumn(0);
|
$offset_days = $r->fetchColumn(0);
|
||||||
|
|
Loading…
Reference in New Issue