-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (61 loc) · 1.35 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const today = new Date();
const days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
function getLastDayName() {
const lastDayIndex = (new Date().getDay() + 6) % 7;
return days[lastDayIndex];
}
function getLastDaysNames(numDays = 7) {
const lastDaysNames = [];
for (let i = 0; i < numDays; i++) {
const day = new Date(
today.getFullYear(),
today.getMonth(),
today.getDate() - i
);
const dayName = days[day.getDay()];
lastDaysNames.unshift(dayName);
}
return lastDaysNames;
}
function getLastMonthName() {
const lastMonthIndex = (new Date().getMonth() + 11) % 12;
return months[lastMonthIndex];
}
function getLastMonthsName(numMonths) {
const lastMonthsNames = [];
for (let i = 0; i < numMonths; i++) {
const month = new Date(today.getFullYear(), today.getMonth() - i, 1);
const monthName = months[month.getMonth()];
lastMonthsNames.unshift(monthName);
}
return lastMonthsNames;
}
module.exports = {
getLastDayName,
getLastMonthName,
getLast7DaysName: () => getLastDaysNames(7),
getLast6MonthsNames: () => getLastMonthsName(6),
getLast12MonthsNames: () => getLastMonthsName(12),
};