2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-08-21 00:17:14 +00:00
|
|
|
angular.module('forms').service('TimeCounter', [
|
2015-06-29 22:51:29 +00:00
|
|
|
function(){
|
2016-06-07 00:37:09 +00:00
|
|
|
var _startTime, _endTime = null, that=this;
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-06-30 02:14:43 +00:00
|
|
|
this.timeSpent = 0;
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-11-23 19:19:02 +00:00
|
|
|
this.restartClock = function(){
|
2015-06-29 22:51:29 +00:00
|
|
|
_startTime = Date.now();
|
2016-06-07 00:37:09 +00:00
|
|
|
_endTime = null;
|
2015-07-02 03:50:57 +00:00
|
|
|
// console.log('Clock Started');
|
2015-06-29 22:51:29 +00:00
|
|
|
};
|
|
|
|
|
2016-06-07 00:37:09 +00:00
|
|
|
this.getTimeElapsed = function(){
|
|
|
|
if(_startTime) {
|
|
|
|
return Math.abs(Date.now().valueOf() - _startTime.valueOf()) / 1000;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
this.stopClock = function(){
|
2016-06-07 00:37:09 +00:00
|
|
|
if(_startTime && _endTime === null){
|
2015-11-23 19:19:02 +00:00
|
|
|
_endTime = Date.now();
|
2016-06-07 00:37:09 +00:00
|
|
|
this.timeSpent = Math.abs(_endTime.valueOf() - _startTime.valueOf())/1000;
|
|
|
|
this._startTime = this._endTime = null;
|
|
|
|
|
|
|
|
return this.timeSpent;
|
2015-11-23 19:19:02 +00:00
|
|
|
}else{
|
|
|
|
return new Error('Clock has not been started');
|
|
|
|
}
|
2015-06-29 22:51:29 +00:00
|
|
|
};
|
|
|
|
|
2015-11-23 19:19:02 +00:00
|
|
|
this.clockStarted = function(){
|
|
|
|
return !!this._startTime;
|
2015-11-23 21:06:02 +00:00
|
|
|
};
|
2015-11-23 19:19:02 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
2016-06-07 00:37:09 +00:00
|
|
|
]);
|