quasarframework/quasar · error · Error
date isSameDate unknown unit ${unit}
Error message
date isSameDate unknown unit ${unit} What it means
Quasar's internal date utils (isSameDate and friends) accept a unit string such as 'year', 'month', 'day'. When the unit does not match any known case, the switch's default branch throws this Error. This indicates a bug or an unsupported unit passed into the date comparison utility, not a user-input validation error.
Source
Thrown at ui/src/utils/date/date.js:838
if (t.getDate() !== d.getDate()) {
return false
}
}
case 'month': // oxlint-disable-line no-fallthrough
case 'months': {
if (t.getMonth() !== d.getMonth()) {
return false
}
}
case 'year': // oxlint-disable-line no-fallthrough
case 'years': {
if (t.getFullYear() !== d.getFullYear()) {
return false
}
break
}
default: {
throw new Error(`date isSameDate unknown unit ${unit}`)
}
}
return true
}
export function daysInMonth(date, utc) {
const prefix = utc ? 'UTC' : '',
t = new Date(date)
t[`set${prefix}Date`](1)
t[`set${prefix}Month`](t[`get${prefix}Month`]() + 1)
t[`set${prefix}Date`](0)
return t[`get${prefix}Date`]()
}
function getOrdinal(n) {View on GitHub (pinned to 4841521b5f)
Solutions
- Use only supported units: 'year', 'month', 'day' (check the switch cases in ui/src/utils/date/date.js).
- Lowercase/normalize the unit before passing: unit.toLowerCase().
- Implement unsupported units yourself (e.g. compare weeks by comparing start-of-week days).
- Report/verify against the Quasar version — newer versions may add units.
Example fix
// before isSameDate(d1, d2, 'week') // unknown unit, throws // after isSameDate(d1, d2, 'day') // use a supported unit
Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED_UNITS = ['year', 'month', 'day']
if (!SUPPORTED_UNITS.includes(unit)) {
throw new Error(`Unsupported date unit: ${unit}`)
} Type guard
const isSupportedUnit = (u) => u === 'year' || u === 'month' || u === 'day'
Try / catch
let same
try {
same = compareDates(d1, d2, unit)
} catch (err) {
if (err instanceof Error && /unknown unit/.test(err.message)) {
console.warn(`Unit '${unit}' not supported, falling back to 'day'`)
same = compareDates(d1, d2, 'day')
} else throw err
} Prevention
- Only use units the Quasar date util supports; do not assume date-fns/moment unit names.
- Normalize units to lowercase before passing.
- Map third-party units to supported ones (e.g. 'week' -> day-level logic).
- Pin the Quasar version and re-check supported units after upgrades.
When it happens
Trigger: Calling internal date comparison helpers (via utils.isSameDate-style code paths) with a unit like 'week', 'hour', or a misspelled/uppercased value ('Year', 'days') that has no matching switch case.
Common situations: Passing units copied from other date libraries (date-fns/moment support many more units than Quasar's util); capitalization mismatches; dynamic units derived from user config; calling private helpers not part of the public API surface.
Related errors
- Expected a string or a {r, g, b[, a]} object as bgColor
- Expected offset to be between -1 and 1
- Expected a string as propName
- Expected a DOM element
- Expected a string as propName
AI-assisted analysis of quasarframework/quasar@4841521b5f (2026-08-30).
Data as JSON: /api/errors/8a06027ccbf8461a.
Report an issue: GitHub.