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

  1. Use only supported units: 'year', 'month', 'day' (check the switch cases in ui/src/utils/date/date.js).
  2. Lowercase/normalize the unit before passing: unit.toLowerCase().
  3. Implement unsupported units yourself (e.g. compare weeks by comparing start-of-week days).
  4. 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

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


AI-assisted analysis of quasarframework/quasar@4841521b5f (2026-08-30). Data as JSON: /api/errors/8a06027ccbf8461a. Report an issue: GitHub.