-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountdown.js
More file actions
38 lines (38 loc) · 910 Bytes
/
Copy pathcountdown.js
File metadata and controls
38 lines (38 loc) · 910 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
35
36
37
38
export default class Countdown {
constructor(futureDate) {
this.futureDate = futureDate;
}
get _futureDate() {
return new Date(this.futureDate);
}
get _currentDate() {
return new Date();
}
get _timeStampDiff() {
return this._futureDate.getTime() - this._currentDate.getTime();
}
get days() {
return Math.floor(this._timeStampDiff / (24 * 60 * 60 * 1000));
}
get hours() {
return Math.floor(this._timeStampDiff / (60 * 60 * 1000));
}
get minutes() {
return Math.floor(this._timeStampDiff / (60 * 1000));
}
get seconds() {
return Math.floor(this._timeStampDiff / 1000);
}
get total() {
const days = this.days;
const hours = this.hours % 24;
const minutes = this.minutes % 60;
const seconds = this.seconds % 60;
return {
days,
hours,
minutes,
seconds,
};
}
}