Files
bedolaga-cabinet/src/utils/period.ts
c0mrade 9a05f23a04 feat(sales-stats): пресет «Этот месяц» (с 1-го числа) и он же по умолчанию
Статистика по умолчанию открывается за текущий месяц с 1-го числа до сегодня
(month-to-date), а не за фиксированные 30 дней. Добавлена кнопка «Этот месяц»
в селектор периода; util getMonthToDateRange/isMonthToDate.
2026-06-02 15:55:10 +03:00

23 lines
893 B
TypeScript

/** First day of the current month → today, as local YYYY-MM-DD strings.
* Used as the default sales-stats window ("this month so far"). */
export function getMonthToDateRange(): { startDate: string; endDate: string } {
const now = new Date();
const toLocalISODate = (d: Date) =>
`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
return {
startDate: toLocalISODate(new Date(now.getFullYear(), now.getMonth(), 1)),
endDate: toLocalISODate(now),
};
}
/** True when the period is exactly "from the 1st of the current month to today". */
export function isMonthToDate(period: {
days?: number;
startDate?: string;
endDate?: string;
}): boolean {
if (period.days !== undefined) return false;
const mtd = getMonthToDateRange();
return period.startDate === mtd.startDate && period.endDate === mtd.endDate;
}