CC-2418: Show add: end time shown in display is not the time committed to DB

This commit is contained in:
martin 2011-06-22 11:21:26 -04:00
parent 34ced48076
commit 50cde2f8b0
2 changed files with 31 additions and 20 deletions

View File

@ -543,8 +543,14 @@ class ScheduleController extends Zend_Controller_Action
if($when) {
$when = $formWhen->checkReliantFields($data, $startDateModified);
}
// format add_show_duration value to hh:mm so it can be compatible with
// existing code
//The way the following code works is that is parses the hour and
//minute from a string with the format "1h 20m" or "2h" or "36m".
//So we are detecting whether an hour or minute value exists via strpos
//and then parse appropriately. A better way to do this in the future is
//actually pass the format from javascript in the format hh:mm so we don't
//have to do this extra String parsing.
$hPos = strpos($data["add_show_duration"], 'h');
$mPos = strpos($data["add_show_duration"], 'm');
@ -555,7 +561,8 @@ class ScheduleController extends Zend_Controller_Action
$hValue = trim(substr($data["add_show_duration"], 0, $hPos));
}
if($mPos !== false){
$mValue = trim(substr($data["add_show_duration"], $hPos+1, -1 ));
$hPos = $hPos === FALSE ? 0 : $hPos+1;
$mValue = trim(substr($data["add_show_duration"], $hPos, -1 ));
}
$data["add_show_duration"] = $hValue.":".$mValue;

View File

@ -317,37 +317,41 @@ function setAddShowEvents() {
}
});
});
// when start date/time changes, set end date/time to start date/time+1 hr
$('#add_show_start_date, #add_show_start_time').change(function(){
var startDate = $('#add_show_start_date').val().split('-');
var startDateTime = new Date(startDate[1]+' '+startDate[2]+','+startDate[0]+' '+$('#add_show_start_time').val());
var startTime = $('#add_show_start_time').val().split(':');
var startDateTime = new Date(startDate[0], parseInt(startDate[1])-1, startDate[2], startTime[0], startTime[1], 0, 0);
var endDate = $('#add_show_end_date_no_repeat').val().split('-');
var endDateTime = new Date(endDate[1]+' '+endDate[2]+','+endDate[0]+' '+$('#add_show_end_time').val());
var endTime = $('#add_show_end_time').val().split(':');
var endDateTime = new Date(endDate[0], parseInt(endDate[1])-1, endDate[2], endTime[0], endTime[1], 0, 0);
if(startDateTime.getTime() > endDateTime.getTime()){
endDateTime = new Date(startDateTime.getTime() + (1*60*60*1000));
}
var endDateFormat = endDateTime.getFullYear() + '-' + pad(endDateTime.getMonth()+1,2) + '-' + pad(endDateTime.getDate(),2);
var endTimeFormat = pad(endDateTime.getHours(),2) + ':' + pad(endDateTime.getMinutes(),2);
$('#add_show_end_date_no_repeat').val(endDateFormat);
$('#add_show_end_time').val(endTimeFormat);
// calculate duration
calculateDuration(endDateTime, startDateTime);
});
// when end date/time changes, check if the changed date is in past of start date/time
$('#add_show_end_date_no_repeat, #add_show_end_time').change(function(){
var startDate = $('#add_show_start_date').val().split('-');
var startDateTime = new Date(startDate[1]+' '+startDate[2]+','+startDate[0]+' '+$('#add_show_start_time').val());
var startTime = $('#add_show_start_time').val().split(':');
var startDateTime = new Date(startDate[0], parseInt(startDate[1])-1, startDate[2], startTime[0], startTime[1], 0, 0);
var endDate = $('#add_show_end_date_no_repeat').val().split('-');
var endDateTime = new Date(endDate[1]+' '+endDate[2]+','+endDate[0]+' '+$('#add_show_end_time').val());
var endTime = $('#add_show_end_time').val().split(':');
var endDateTime = new Date(endDate[0], parseInt(endDate[1])-1, endDate[2], endTime[0], endTime[1], 0, 0);
if(startDateTime.getTime() > endDateTime.getTime()){
$('#add_show_end_date_no_repeat').css('background-color', '#F49C9C');
$('#add_show_end_time').css('background-color', '#F49C9C');
@ -355,11 +359,11 @@ function setAddShowEvents() {
$('#add_show_end_date_no_repeat').css('background-color', '');
$('#add_show_end_time').css('background-color', '');
}
// calculate duration
calculateDuration(endDateTime, startDateTime);
});
function calculateDuration(endDateTime, startDateTime){
var duration;
var durationSeconds = (endDateTime.getTime() - startDateTime.getTime())/1000;
@ -372,13 +376,13 @@ function setAddShowEvents() {
}
$('#add_show_duration').val(duration);
}
function pad(number, length) {
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
}
}