mercury-web/src/features/accounting/monthRange.ts
Munkherdene e478ca5826 feat(web): transactions month nav + category filters + categorize-review queue
Adds a month navigator and category filter chips to the Тооцоо list, plus a
categorize-review flow at /accounting/review for bulk-assigning categories to
uncategorized merchants (grouped by matchKey, biggest spend first).
2026-08-22 23:00:09 +08:00

22 lines
1,018 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { todayLocalDate } from "@/api/hooks/reads";
/**
* Local-calendar [from, to] bounds (`YYYY-MM-DD`, matching `?from=&to=`) for
* the month `offset` months from `base` — 0 = `base`'s own month, -1 = the
* month before, +1 = the month after. Powers the Тооцоо month navigator.
*/
export function monthRange(offset: number, base: Date = new Date()): { from: string; to: string } {
const year = base.getFullYear();
const month = base.getMonth() + offset;
const first = new Date(year, month, 1);
const last = new Date(year, month + 1, 0); // day 0 of next month = this month's last day
return { from: todayLocalDate(first), to: todayLocalDate(last) };
}
/** "2026 оны 8-р сар" for the month `offset` months from `base`. */
export function monthLabel(offset: number, base: Date = new Date()): string {
const year = base.getFullYear();
const month = base.getMonth() + offset;
const d = new Date(year, month, 1);
return `${d.getFullYear()} оны ${d.getMonth() + 1}-р сар`;
}