This commit is contained in:
Mateusz Gruszczyński
2026-04-06 10:46:48 +02:00
parent 1ba1a26291
commit 0c7414101a
23 changed files with 962 additions and 355 deletions

View File

@@ -29,16 +29,23 @@ const defaultPrefs = (email: string) => ({
categoryIds: [] as string[]
});
const formatLocalDate = (date: Date) => {
const year = date.getFullYear();
const month = `${date.getMonth() + 1}`.padStart(2, '0');
const day = `${date.getDate()}`.padStart(2, '0');
return `${year}-${month}-${day}`;
};
const periodRange = (frequency: 'monthly' | 'yearly' | 'threshold') => {
const now = new Date();
const endDate = now.toISOString().slice(0, 10);
const endDate = formatLocalDate(now);
if (frequency === 'yearly') {
return { startDate: `${now.getUTCFullYear()}-01-01`, endDate, bucket: 'month' as const, label: 'Year to date' };
return { startDate: `${now.getFullYear()}-01-01`, endDate, bucket: 'month' as const, label: 'Year to date' };
}
const start = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
return { startDate: start.toISOString().slice(0, 10), endDate, bucket: 'month' as const, label: 'Current month' };
const start = new Date(now.getFullYear(), now.getMonth(), 1);
return { startDate: formatLocalDate(start), endDate, bucket: 'month' as const, label: 'Current month' };
};
const buildReportHtml = (title: string, summary: Awaited<ReturnType<typeof getStatistics>>) => {