-
Notifications
You must be signed in to change notification settings - Fork 0
/
date.js
65 lines (46 loc) · 1.04 KB
/
date.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Wrapper around the Date object to add intuitive math functions
DateMath = function() {
var internal = new Date();
return {
addYears: function(n) {
internal.setYear(internal.getFullYear()+n);
},
getInternal: function() {
return internal;
},
getDate: function() {
return internal.getDate();
},
setDate: function(d) {
internal.setDate(d);
},
setInternal: function(o) {
internal = angular.copy(o);
}
}; //return
}; //DateMath
RandomDateGenerator = function() {
// member variables
var minDate = new Date();
var maxDate = new Date();
var randomFunction = Math.random;
return {
setMinimum: function(value) {
minDate = value;
},
setMaximum: function(value) {
maxDate = value;
},
setMaximumNow: function() {
maxDate = new Date(Date.now());
},
setRandomFunction: function(value) {
randomFunction = value;
},
makeDate: function() {
d = new Date();
d.setTime(maxDate.getTime() - (maxDate.getTime()-minDate.getTime())*randomFunction());
return d;
}
};
}