UNPKG

@baruchiro/actual-mcp

Version:

Actual Budget MCP server exposing API functionality

47 lines (46 loc) 1.44 kB
/** * Get date range parameters with defaults */ export function getDateRange(startDate, endDate) { const today = new Date(); const defaultStartDate = new Date(); defaultStartDate.setMonth(today.getMonth() - 3); // 3 months ago by default return { startDate: startDate || formatDate(defaultStartDate), endDate: endDate || formatDate(today), }; } /** * Format a date as YYYY-MM-DD */ export function formatDate(date) { if (!date) return ""; if (typeof date === "string") return date; const d = new Date(date); return d.toISOString().split("T")[0]; } /** * Format currency amounts for display */ export function formatAmount(amount) { if (amount === undefined || amount === null) return "N/A"; // Convert from cents to dollars const dollars = amount / 100; return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", }).format(dollars); } // Helper to calculate start/end date strings for the N most recent months export function getDateRangeForMonths(months) { const now = new Date(); const end = new Date(now.getFullYear(), now.getMonth() + 1, 0); // last day of current month const start = new Date(end.getFullYear(), end.getMonth() - months + 1, 1); // first day of N months ago return { start: start.toISOString().slice(0, 10), end: end.toISOString().slice(0, 10), }; }