Fix for #2150 - SNAP TO NEXT does not work properly. It looks like the javascript DATE object changes the time you give it depending on your offset to GMT. I added a function to calculate the number of milliseconds in times directly instead of relying on the Date object.

This commit is contained in:
paul 2007-02-16 13:03:12 +00:00
parent a78fc227a4
commit 49e3f2f717
1 changed files with 41 additions and 9 deletions

View File

@ -47,25 +47,57 @@ function SCHEDULE_snap2Prev()
{literal}
}
/**
* Take a string as input in the form "HH:MM:SS" and return
* the number of milliseconds this represents from the time
* "00:00:00".
*
* @param string p_timeString
* @return int
*/
function SCHEDULE_timeToMilliseconds(p_timeString)
{
{/literal}
if (p_timeString.length != 8) return 0;
var arr = p_timeString.split(":");
if (arr.length != 3) return 0;
// hours
milliseconds = arr[0]*60*60*1000;
// minutes
milliseconds += arr[1]*60*1000;
// seconds
milliseconds += arr[2]*1000;
return milliseconds;
{literal}
}
function SCHEDULE_snap2Next()
{
{/literal}
// Get the absolute "next item" time, meaning how many milliseconds from
// the beginning of the day that the next item starts.
var nextItemTime = new Date("january 01, 1970 {$SCHEDULER->scheduleNext.hour}:{$SCHEDULER->scheduleNext.minute}:{$SCHEDULER->scheduleNext.second}");
// Get the number of milliseconds from the beginning of the day
// that the next item in the schedule starts.
var nextItemTime = SCHEDULE_timeToMilliseconds("{$SCHEDULER->scheduleNext.hour}:{$SCHEDULER->scheduleNext.minute}:{$SCHEDULER->scheduleNext.second}");
// Get the absolute duration of the playlist in Date format (milliseconds)
var duration = new Date("january 01, 1970 " + SCHEDULE_selectedDuration());
// Get the duration of the item to be scheduled in milliseconds.
var duration = SCHEDULE_timeToMilliseconds(SCHEDULE_selectedDuration());
// Get the date of the "next item".
// Get the date of the "next item" (time is set to midnight).
var beginDate = new Date({$SCHEDULER->scheduleNext.year},
{$SCHEDULER->scheduleNext.month},
{$SCHEDULER->scheduleNext.day});
//debugBeginDate = ""+beginDate;
// Calculate the final time by starting with the "next item" date (midnight),
// add in milliseconds to the starting time of the "next item",
// Calculate the final time by starting with the "next item" date at midnight,
// add in milliseconds midnight to "next item" start time,
// subtract the duration of the selected playlist.
beginDate.setTime(beginDate.getTime() + nextItemTime.getTime() - duration.getTime());
beginDate.setTime(beginDate.getTime() + nextItemTime - duration);
//alert("next item time: "+nextItemTime+"\n"
// +"duration: "+(duration)+"\n"
// +"debug begin date: "+debugBeginDate+"\n"
// +"begin date: "+beginDate+"\n");
document.forms["schedule"].elements["time[H]"].value = beginDate.getHours();
document.forms["schedule"].elements["time[i]"].value = beginDate.getMinutes();
document.forms["schedule"].elements["time[s]"].value = beginDate.getSeconds();