Supports more

This commit is contained in:
2024-12-16 21:55:06 -08:00
parent b7826ad6ce
commit da2702f9e8
5 changed files with 83 additions and 35 deletions

View File

@@ -184,6 +184,41 @@ function getFourWeekPeriodsPeriods(endDate) {
];
}
const getTwelveCalendarMonthsPeriods = (endDate) => {
console.log(endDate)
// If no date is provided, default to today's date
const today = endDate ? parseMMDDYYYY(endDate) : new Date();
// Set the last day of the provided month as the end date
const inputEndDate = new Date(today.getFullYear(), today.getMonth() + 1, 0);
// Calculate the start of the total year range (12 months back from the end of input month)
const totalStartDate = new Date(inputEndDate.getFullYear(), inputEndDate.getMonth() - 11, 1);
// Build the array of months
// Build the array of months
const months = [
{
start: formatDateMMDDYYYY(totalStartDate),
end: formatDateMMDDYYYY(inputEndDate),
title: "Total"
},
...Array.from({ length: 12 }, (_, i) => {
const monthEnd = new Date(inputEndDate.getFullYear(), inputEndDate.getMonth() - (11 - i) + 1, 0); // Last day of the month
const monthStart = new Date(monthEnd.getFullYear(), monthEnd.getMonth(), 1); // First day of the month
return {
start: formatDateMMDDYYYY(monthStart),
end: formatDateMMDDYYYY(monthEnd),
title: monthEnd.toLocaleString('default', { month: 'long', year: 'numeric' })
};
})
];
console.log(months)
return months;
};
const withLastYear = (date) => {
if (!date) {