-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdates.js
64 lines (55 loc) · 1.42 KB
/
dates.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
function getLastDayOfTheCurrentMonth(nextMonth = 1) {
const currentDate = new Date();
const dateFormat = { month: "short", day: "numeric", year: "numeric" };
const lastDayOfTheMonth = new Date(
currentDate.getFullYear(),
currentDate.getMonth() + nextMonth,
0
);
return lastDayOfTheMonth.toLocaleDateString("en-US", dateFormat);
}
function getTenthDayOfTheMonth(
nextMonth = 1,
firstDayOfTheMonth = 1,
tenthDayOfTheMonth = 10
) {
const currentDate = new Date();
const dateFormat = { month: "short", day: "numeric", year: "numeric" };
const firstDayOfTheNextMonth = new Date(
currentDate.getFullYear(),
currentDate.getMonth() + nextMonth,
firstDayOfTheMonth
);
const tenthDayOfTheNextMonth = new Date(
firstDayOfTheNextMonth.getFullYear(),
firstDayOfTheNextMonth.getMonth(),
tenthDayOfTheMonth
);
return tenthDayOfTheNextMonth.toLocaleDateString("en-US", dateFormat);
}
function getLastMonthFromNow() {
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
const currentMonth = new Date().getMonth();
const pastMonth = (currentMonth - 1 + 12) % 12;
return months[pastMonth];
}
const currentYear = new Date().getFullYear();
module.exports = {
getLastDayOfTheCurrentMonth,
getTenthDayOfTheMonth,
getLastMonthFromNow,
currentYear,
};