forked from exercism/DEPRECATED.javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
34 lines (26 loc) · 651 Bytes
/
example.js
File metadata and controls
34 lines (26 loc) · 651 Bytes
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
exports.at = at;
function at(hours, minutes) {
var min = 1000 * 60;
var hr = min * 60;
var clock = {};
var value = (~~hours * hr) + (~~minutes * min);
clock.valueOf = function () {
return value;
};
clock.toString = function () {
var time = new Date(value).toISOString().split('T')[1].split(':');
return time[0] + ":" + time[1];
};
clock.plus = function (minutes) {
value += ~~minutes * min;
return clock;
};
clock.minus = function (minutes) {
value -= ~~minutes * min;
return clock;
};
clock.equals = function (other) {
return +clock === +other;
};
return Object.create(clock);
};