-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdates.js
More file actions
44 lines (41 loc) · 1.37 KB
/
Copy pathdates.js
File metadata and controls
44 lines (41 loc) · 1.37 KB
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
export function calculateRevisionDates(dateString) {
const [year, month, day] = dateString.split("-").map(Number);
const addWeeks = (y, m, d, weeks) => {
const date = new Date(Date.UTC(y, m - 1, d + weeks * 7));
return formatDate(date);
};
const addMonths = (y, m, d, months) => {
const date = new Date(Date.UTC(y, m - 1 + months, d));
return formatDate(date);
};
return [
addWeeks(year, month, day, 1),
addMonths(year, month, day, 1),
addMonths(year, month, day, 3),
addMonths(year, month, day, 6),
addMonths(year, month, day, 12),
];
}
export function formatDate(date) {
const y = date.getUTCFullYear();
const m = String(date.getUTCMonth() + 1).padStart(2, "0");
const d = String(date.getUTCDate()).padStart(2, "0");
return `${y}-${m}-${d}`;
}
export function stringifiedTodayDate() {
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, "0");
const day = String(today.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
}
export function upcomingItems(agendaItems) {
const today = stringifiedTodayDate();
const upcomingItems = agendaItems.filter((agendaItem) => {
return agendaItem.date >= today;
});
const sortedUpcomingItems = upcomingItems.toSorted((a, b) => {
return a.date.localeCompare(b.date);
});
return sortedUpcomingItems;
}