tellform/public/modules/forms/services/time-counter.client.service.js

31 lines
636 B
JavaScript
Raw Normal View History

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(){
var _startTime, _endTime, that=this;
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();
2015-11-23 19:19:02 +00:00
_endTime = _startTime;
2015-07-02 03:50:57 +00:00
// console.log('Clock Started');
2015-06-29 22:51:29 +00:00
};
this.stopClock = function(){
2015-11-23 19:19:02 +00:00
if(_startTime){
_endTime = Date.now();
that.timeSpent = Math.abs(_endTime.valueOf() - _startTime.valueOf())/1000;
// console.log('Clock Ended');
return that.timeSpent;
}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
}
]);