cube-js/cube · error · UserError
Can't parse date: '${dateString}'
Error message
Can't parse date: '${dateString}' What it means
When dateParser receives a dateRange string that matches none of the special patterns (this/last/next, today/yesterday/tomorrow, 'from ... to ...'), it falls back to chrono-node parsing of the whole string. If chrono returns no results the entire string is not a recognized date expression and Cube throws this UserError.
Source
Thrown at packages/cubejs-api-gateway/src/date-parser.js:96
}
if (!Array.isArray(toResults) || !toResults.length) {
throw new UserError(`Can't parse date: '${to}'`);
}
const exactGranularity = ['second', 'minute', 'hour'].find(g => dateString.indexOf(g) !== -1) || 'day';
momentRange = [
momentFromResult(fromResults[0].start, timezone),
momentFromResult(toResults[0].start, timezone)
];
momentRange = [momentRange[0].startOf(exactGranularity), momentRange[1].endOf(exactGranularity)];
} else {
const current = moment(now).tz(timezone);
const results = parse(dateString, new Date(current.format(moment.HTML5_FMT.DATETIME_LOCAL_MS)));
if (!results?.length) {
throw new UserError(`Can't parse date: '${dateString}'`);
}
const exactGranularity = ['second', 'minute', 'hour'].find(g => dateString.indexOf(g) !== -1) || 'day';
momentRange = results[0].end ? [
momentFromResult(results[0].start, timezone),
momentFromResult(results[0].end, timezone)
] : [
momentFromResult(results[0].start, timezone),
momentFromResult(results[0].start, timezone)
];
momentRange = [momentRange[0].startOf(exactGranularity), momentRange[1].endOf(exactGranularity)];
}
return momentRange.map(d => d.format(moment.HTML5_FMT.DATETIME_LOCAL_MS));
}
View on GitHub (pinned to 7d981676b3)
Solutions
- Use an ISO 8601 string like '2024-12-31' or a ['start','end'] ISO array for dateRange — these are handled reliably
- Use one of the supported relative expressions: 'today', 'yesterday', 'tomorrow', 'last month', 'last 30 days', 'this quarter'
- Pre-validate the string with chrono-node (parse returns an empty array when it will fail) before sending the query
- Convert locale-formatted dates to ISO in client code instead of relying on natural-language parsing
Example fix
// before
{ dateRange: ['31/12/2024'] }
// after
{ dateRange: ['2024-12-31'] } Defensive patterns
Strategy: validation
Validate before calling
import { parse } from 'chrono-node';
const SUPPORTED = /^(this|last|next)\s+(day|week|month|year|quarter|hour|minute|second)$|^(last|next)\s+\d+\s+(day|week|month|year|quarter|hour|minute|second)$|^today$|^yesterday$|^tomorrow$/i;
const isValidDateRangeString = (s) => typeof s === 'string' && (SUPPORTED.test(s.trim()) || parse(s.trim()).length > 0); Type guard
const isKnownRangeExpression = (s) => typeof s === 'string' && /^(this|last|next)\s+(day|week|month|year|quarter|hour|minute|second)|(last|next)\s+\d+\s+(day|week|month|year|quarter|hour|minute|second)|today|yesterday|tomorrow|from .+ to .+/i.test(s.trim());
Try / catch
try {
return await cube.load({ ...query, dateRange: [rangeString] });
} catch (e) {
if (e instanceof Error && e.message.startsWith("Can't parse date:")) {
return cube.load({ ...query, dateRange: [defaultStart, defaultEnd] });
}
throw e;
} Prevention
- Use ISO strings or ISO arrays for dateRange — the natural-language parser (chrono-node) only understands English
- Check strings against the supported patterns (today/yesterday/tomorrow, this|last|next unit, from X to Y) before sending
- Convert locale dates to ISO in client code
- Pre-run chrono.parse() on any dynamic range string
When it happens
Trigger: Passing a single dateRange string chrono cannot parse, e.g. dateRange: ['31/12/2024'] in an ambiguous format, [''] (empty), ['2024'], ['next fortnight'], or a non-English expression like ['letzter monat'].
Common situations: Non-English locale date strings; day-first formats chrono misinterprets; empty strings from unset dashboard filters; strings built with toLocaleDateString(); users typing free-form ranges like 'last quarter to date' that match no pattern and no chrono result.
Related errors
- Can't parse date: '${from}'
- Can't parse date: '${to}'
- Cannot parse selector date range ${selector.dateRange}
- Invalid Job query format: ${error.message || error.toString(
- provide --file <path> or --content <text>
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/7ff8bbd8387cbb8f.
Report an issue: GitHub.