actualbudget/actual · error

Invalid date format provided

Error message

Invalid date format provided

What it means

summarySpreadsheet parses the start/end month strings into Date objects using monthUtils helpers plus date-fns d.parse with 'yyyy-MM-dd'. If those helpers or the parse throw (malformed input), the error is caught and rethrown as 'Invalid date format provided'. It signals the caller that the date strings supplied to the report are unparseable.

Source

Thrown at packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts:62

    let endDay: Date;
    try {
      startDay = d.parse(
        monthUtils.firstDayOfMonth(start),
        'yyyy-MM-dd',
        new Date(),
      );

      endDay = d.parse(
        monthUtils.getMonth(end) ===
          monthUtils.getMonth(monthUtils.currentDay())
          ? monthUtils.currentDay()
          : monthUtils.lastDayOfMonth(end),
        'yyyy-MM-dd',
        new Date(),
      );
    } catch (error) {
      console.error('Error parsing dates:', error);
      throw new Error('Invalid date format provided');
    }

    if (!d.isValid(startDay) || !d.isValid(endDay)) {
      throw new Error('Invalid date values provided');
    }

    if (d.isAfter(startDay, endDay)) {
      throw new Error('Start date must be before or equal to end date.');
    }

    const getOneDatePerMonth = (start: Date, end: Date) => {
      const months = [];
      let currentDate = d.startOfMonth(start);

      while (!d.isSameMonth(currentDate, end)) {
        months.push(currentDate);
        currentDate = d.addMonths(currentDate, 1);
      }

View on GitHub (pinned to d4334cb6e6)

Solutions

  1. Inspect and correct the start/end values to valid 'yyyy-MM' month strings
  2. Validate with /^\d{4}-\d{2}$/ (and a real month 01-12) before calling summarySpreadsheet
  3. If dates come from a saved report, edit the report's date range in the UI to reset them
  4. Wrap the call in try/catch and fall back to a sane default range

Example fix

// before
summarySpreadsheet('2024-05-01T00:00:00Z', end, conditions, op, content, locale);
// after
summarySpreadsheet('2024-05', end, conditions, op, content, locale); // yyyy-MM month strings
Defensive patterns

Strategy: validation

Validate before calling

const isValidMonth = (s: string) => /^\d{4}-(0[1-9]|1[0-2])$/.test(s);
if (!isValidMonth(start) || !isValidMonth(end)) throw new RangeError('start/end must be yyyy-MM month strings');

Type guard

function isMonthString(v: unknown): v is string {
  return typeof v === 'string' && /^\d{4}-(0[1-9]|1[0-2])$/.test(v);
}

Try / catch

try {
  await summarySpreadsheet(start, end, conditions, op, content, locale)(spreadsheet, setData);
} catch (e) {
  if (e instanceof Error && /Invalid date (format|values)/.test(e.message)) {
    console.warn('Bad report range, using default', { start, end });
  } else throw e;
}

Prevention

When it happens

Trigger: Calling summarySpreadsheet with start or end that is not a valid yyyy-MM month string (e.g. 'foo', '2024-1', empty string), causing monthUtils.firstDayOfMonth/getMonth/lastDayOfMonth or d.parse to throw.

Common situations: Corrupted date range stored in a saved report; an integration passing full ISO timestamps ('2024-05-01T00:00:00Z') or slash-formatted dates where a month string is expected; timezone-related string munging before the call.

Related errors


AI-assisted analysis of actualbudget/actual@d4334cb6e6 (2026-08-29). Data as JSON: /api/errors/432aee65996573f2. Report an issue: GitHub.