-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSsvDate.js
30 lines (29 loc) · 921 Bytes
/
SsvDate.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
class SsvDate {
constructor(year, month, day = 1) {
this.year = Number(year);
this.month = Number(month);
this.day = Number(day);
}
static getCurrent() {
const date = new Date();
return new SsvDate(date.getFullYear(), date.getMonth() + 1, date.getDate());
}
clone() { return new SsvDate(this.year, this.month, this.day); }
cloneAndDecrement() { return this.clone().decrement(); }
getDay() { return this.day; }
getMonth() { return this.month; }
getYear() { return this.year; }
toString() { return this.year + '-' + this.month; }
decrement() {
if (this.month === 1) {
--this.year;
this.month = 12;
}
else {
--this.month;
}
return this;
}
//isSameMonth(date) { this.year === date.getYear() && this.month === date.getMonth(); }
}
module.exports = SsvDate;