-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (35 loc) · 1007 Bytes
/
index.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
var moment = require('moment');
var Cal = function() {
this.moment = moment();
return this;
};
Cal.prototype.now = function() {
return this.moment.toDate();
};
Cal.prototype.setMonth = function(month) {
this.moment.set('month', month - 1);
};
Cal.prototype.setYear = function(year) {
this.moment.set('year', year);
};
Cal.prototype.getYear = function() {
return this.moment.year();
};
Cal.prototype.getMonth = function() {
return this.moment.format('MMMM');
};
Cal.prototype.daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
Cal.prototype.getDaysOfWeekByMonth = function() {
var days = [];
for (var i = 0; i < this.getDaysThisMonth(); i++) {
days.push(this.moment.startOf('month').add(i, 'days').format('dddd'));
}
return days;
};
Cal.prototype.getFirstDayOfMonth = function() {
return this.getDaysOfWeekByMonth()[0];
};
Cal.prototype.getDaysThisMonth = function() {
return this.moment.daysInMonth();
};
module.exports = Cal;