-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDate.js
39 lines (33 loc) · 1.16 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
module.exports =
class CalendarDate {
#months = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"];
#daysWeek = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
constructor(month, year) {
if(month < 1 || month > 12) {
throw "Mois non valide !";
} else if(year < 1970) {
throw "Année inférieure à 1970 / ne correspond pas";
} else if((month < 1 || month > 12) && year < 1970) {
throw "Le mois et l'année sont non valides !";
} else {
this.month = month;
this.year = year;
}
}
monthAndYear() {
return this.#months[this.month - 1] + " " + this.year;
}
numberOfDays() {
let lastDayMonth = new Date(this.year, this.month, 0).getDate();
return lastDayMonth;
}
firstDay() {
let currentDate = new Date(this.year, this.month - 1, 1).toString();
for(let day of this.#daysWeek) {
if(currentDate.slice(0, 3) === day) {
return currentDate.slice(0, 3);
}
}
return this.#daysWeek;
}
};