-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate-utils.js
More file actions
42 lines (35 loc) · 993 Bytes
/
date-utils.js
File metadata and controls
42 lines (35 loc) · 993 Bytes
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
// Global Variables
const todayInEST = new Date().toLocaleString('en-US', {
timeZone: 'America/New_York',
});
const today = new Date(todayInEST);
// Helpers
const isSameDay = (first, second) => {
return (
first.getFullYear() === second.getFullYear() &&
first.getMonth() === second.getMonth() &&
first.getDate() === second.getDate()
);
};
// Utils
export const getYear = () => {
return today.getFullYear();
};
export const getSemester = () => {
return today.getMonth() <= 5 ? 'Spring' : 'Fall';
};
//date format is Month Day, Year eg. "July 24, 2020"
export const isToday = (date) => {
const parsedDate = new Date(date);
return isSameDay(parsedDate, today);
};
//date format is Month Day, Year eg. "July 24, 2020"
export const isPastDate = (date) => {
const parsedDate = new Date(date);
if (isSameDay(parsedDate, today)) {
return false;
} else return parsedDate < today;
};
export const getAbbrvMonth = (month) => {
return month.substring(0, 3);
};