-
Notifications
You must be signed in to change notification settings - Fork 0
/
dayNumber.js
32 lines (26 loc) · 978 Bytes
/
dayNumber.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
const millisecondsPerDay = 8.64e7;
export const currentDayNumber = () => {
const d = new Date(new Date().toDateString()); // remove the time!
return Math.ceil((d.getTime()) / millisecondsPerDay);
}
export const dayNumberToDate = (dayNumber) => {
return new Date(dayNumber * millisecondsPerDay);
}
export const monthName = (d) => {
if (typeof(d) !== "object")
d = dayNumberToDate(d);
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
return months[d.getMonth()];
}
export const dayOfWeekName = (d) => {
if (typeof(d) !== "object")
d = dayNumberToDate(d);
// const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
return days[d.getDay()];
}
export const dayOfMonth = (d) => {
if (typeof(d) !== "object")
d = dayNumberToDate(d);
return d.getDate();
}