/** Convert a Date to SQLite datetime format (YYYY-MM-DD HH:MM:SS) for correct string comparisons. */
function toSqliteDatetime(date) {
    return date.toISOString().replace('T', ' ').replace(/\.\d{3}Z$/, '');
}
/** Parse a SQLite datetime string as UTC (SQLite datetime('now') produces UTC). */
function parseSqliteDatetime(s) {
    // SQLite format: "2026-03-12 12:51:56" — always UTC
    // Add 'Z' to force UTC interpretation
    return new Date(s.replace(' ', 'T') + 'Z');
}
export function getSpendingPeriodStart(resetAt) {
    const now = new Date();
    if (resetAt) {
        const reset = parseSqliteDatetime(resetAt);
        if (reset.getUTCFullYear() === now.getUTCFullYear() &&
            reset.getUTCMonth() === now.getUTCMonth()) {
            return toSqliteDatetime(reset);
        }
    }
    return toSqliteDatetime(new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1)));
}
export function getSpendingPeriodEnd(periodStart) {
    const start = parseSqliteDatetime(periodStart);
    return new Date(Date.UTC(start.getUTCFullYear(), start.getUTCMonth() + 1, 1)).toISOString();
}
//# sourceMappingURL=spending.js.map