{"record":{"id":"e800ec97cdc18844","repo":"jquense/yup","slug":"name-must-be-a-date-or-a-value-that-can-be-c","errorCode":null,"errorMessage":"`${name}` must be a Date or a value that can be `cast()` to a Date","messagePattern":"`(.+?)` must be a Date or a value that can be `cast\\(\\)` to a Date","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/date.ts","lineNumber":70,"sourceCode":"\n        value = parseIsoDate(value);\n\n        // 0 is a valid timestamp equivalent to 1970-01-01T00:00:00Z(unix epoch) or before.\n        return !isNaN(value) ? new Date(value) : DateSchema.INVALID_DATE;\n      });\n    });\n  }\n\n  private prepareParam(\n    ref: unknown | Ref<Date>,\n    name: string,\n  ): Date | Ref<Date> {\n    let param: Date | Ref<Date>;\n\n    if (!Ref.isRef(ref)) {\n      let cast = this.cast(ref);\n      if (!this._typeCheck(cast))\n        throw new TypeError(\n          `\\`${name}\\` must be a Date or a value that can be \\`cast()\\` to a Date`,\n        );\n      param = cast;\n    } else {\n      param = ref as Ref<Date>;\n    }\n    return param;\n  }\n\n  min(min: unknown | Ref<Date>, message = locale.min) {\n    let limit = this.prepareParam(min, 'min');\n\n    return this.test({\n      message,\n      name: 'min',\n      exclusive: true,\n      params: { min },\n      skipAbsent: true,","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/jquense/yup/blob/ff31eee8a2b10c938bb3a22544d9e33957a8cf01/src/date.ts#L52-L88","documentation":"DateSchema's prepareParam (used by limit setters like min/max) accepts either a ref or a concrete value; if it is not a ref, it is cast via this.cast() and the result must pass _typeCheck as a valid Date. Values that cannot be cast to a Date (invalid strings, numbers out of range, arbitrary objects) throw this TypeError naming the parameter (`min` or `max`).","triggerScenarios":"yup.date().min('not-a-date'), .max(someObject), .min(new Date('Invalid')) producing an invalid Date after cast, or a numeric timestamp string in an unexpected format that fails cast.","commonSituations":"Limits loaded from config/env/API as strings in non-ISO formats; passing a dayjs/moment object instead of a native Date or ISO string; timezone-dependent parse failures; new Date(undefined).","solutions":["Pass a valid Date or ISO string: yup.date().min(new Date('2024-01-01')) or .min('2024-01-01T00:00:00Z').","Pre-validate the value: isNaN(Date.parse(v)) check before passing it in.","If using another date library, convert first: .min(dayjs(x).toDate())."],"exampleFix":"// before\nyup.date().min(config.minDate) // config.minDate = '01/2024'\n// after\nyup.date().min(new Date('2024-01-01T00:00:00Z'))","handlingStrategy":"validation","validationCode":"const toLimit = (v) => {\n  const d = v instanceof Date ? v : new Date(v);\n  if (isNaN(d.getTime())) throw new TypeError(`invalid date limit: ${v}`);\n  return d;\n};\nyup.date().min(toLimit(config.minDate));","typeGuard":"const isDateable = (v) => v instanceof Date || (typeof v === 'string' && !isNaN(Date.parse(v))) || typeof v === 'number';","tryCatchPattern":"try {\n  schema = yup.date().min(rawLimit);\n} catch (e) {\n  if (e.message.includes('must be a Date or a value that can be')) {\n    schema = yup.date().min(new Date()); // or surface a config error\n  } else throw e;\n}","preventionTips":["Store date limits as ISO 8601 strings or Date objects in config.","Convert moment/dayjs values with .toDate() before use.","Validate all date limits at config load time, not schema build time."],"tags":["yup","date","cast","type-error"],"backgroundTag":"invalid-date-cast","analyzedSha":"ff31eee8a2b10c938bb3a22544d9e33957a8cf01","analyzedAt":"2026-08-31T21:51:03.773Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}