define('application/managers/progress', [
'antie/runtimecontext'
],
function (
RuntimeContext
) {
'use strict';
var app = RuntimeContext.getCurrentApplication();
return {
/**
* Returns the live progress width.
*
* @param {Date} startTime - The start time.
* @param {Date} endTime - The end time.
* @param {number} pauseTime - The position behind head.
* @returns {{head: number, pause: number}} - The head and pause percentage.
*/
getLiveProgressPercentage: function (startTime, endTime, pauseTime) {
var currentTime = app.getDate(),
behind,
head,
pause,
elapsedTime,
remainingTime;
pauseTime = pauseTime || currentTime;
behind = pauseTime - currentTime;
pauseTime = pauseTime - startTime;
currentTime = currentTime - startTime;
endTime = endTime - startTime;
head = (currentTime * 100) / endTime;
pause = (pauseTime * 100) / endTime;
elapsedTime = (currentTime + behind) / 1000;
remainingTime = (endTime / 1000) - elapsedTime;
return {
elapsedTime: elapsedTime,
remainingTime: remainingTime,
head: head,
secondHead: pause,
behind: behind // behind
};
},
/**
* Returns the live progress width.
*
* @param {Date} startTime - The start time.
* @param {Date} endTime - The end time.
* @param {number} restartDifference - The position behind head.
* @returns {{head: number, pause: number}} - The head and pause percentage.
*/
getRestartProgressPercentage: function (startTime, endTime, restartDifference) {
var currentTime,
head,
secondHead,
restartTime,
elapsedTime,
remainingTime;
currentTime = app.getDate();
endTime = endTime - startTime;
restartTime = currentTime - restartDifference;
restartTime = restartTime - startTime;
currentTime = currentTime - startTime;
secondHead = (restartTime * 100) / endTime;
head = (currentTime * 100) / endTime;
elapsedTime = (currentTime - restartDifference) / 1000;
remainingTime = (endTime / 1000) - elapsedTime;
return {
elapsedTime: elapsedTime,
remainingTime: remainingTime,
head: head,
pause: 0,
secondHead: secondHead,
behind: -restartDifference // behind
};
},
/**
* Returns the live progress width.
*
* @param {Date} startTime - The start time.
* @param {Date} endTime - The end time.
* @param {number} width - The progress bar width.
* @param {number} pauseTime - The position behind head.
* @returns {{head: number, pause: number}} - The head and pause width.
*/
getLiveProgressWidth: function (startTime, endTime, width, pauseTime) {
var percentages = this.getLiveProgressPercentage(startTime, endTime, pauseTime);
return {
head: (width / 100) * percentages.head,
pause: (width / 100) * percentages.pause
};
}
};
});