forked from MiguelCastillo/Brackets-InteractiveLinter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.js
48 lines (34 loc) · 700 Bytes
/
timer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* rjasmine Copyright (c) 2015 Miguel Castillo.
* Licensed under MIT
*
* https://github.com/MiguelCastillo/rjasmine
*/
define(function() {
"use strict";
function Timer(start) {
if(start !== false) {
this.start();
}
}
Timer.units = {
msec: 1,
secs: 1000,
mins: 1000 * 60,
hours: 1000 * 60 * 60
};
Timer.prototype.start = function() {
this._start = Date.now();
};
Timer.prototype.end = function() {
this._end = Date.now();
};
Timer.prototype.elapsed = function(unit) {
if (isNaN(unit) === true) {
unit = Timer.units.secs;
}
this.end();
return (this._end - this._start)/unit;
};
return Timer;
});