{"record":{"id":"1519aa9317b5c8a0","repo":"hexojs/hexo","slug":"value-is-not-a-valid-date","errorCode":null,"errorMessage":"`${value}` is not a valid date!","messagePattern":"`(.+?)` is not a valid date!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/models/types/moment.ts","lineNumber":33,"sourceCode":"  constructor(name, options = {}) {\n    super(name, options);\n  }\n\n  cast(value?, data?) {\n    value = super.cast(value, data);\n    if (value == null) return value;\n\n    return toMoment(value);\n  }\n\n  validate(value, data?) {\n    value = super.validate(value, data);\n    if (value == null) return value;\n\n    value = toMoment(value);\n\n    if (!value.isValid()) {\n      throw new Error('`' + value + '` is not a valid date!');\n    }\n\n    return value;\n  }\n\n  match(value, query, _data?) {\n    return value ? value.valueOf() === query.valueOf() : false;\n  }\n\n  compare(a?, b?) {\n    if (a) {\n      if (b) return a - b;\n      return 1;\n    }\n\n    if (b) return -1;\n    return 0;\n  }","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/hexojs/hexo/blob/059cb17494d0632a053c24077f5bcb6ae92acc51/lib/models/types/moment.ts#L15-L51","documentation":"Thrown by SchemaTypeMoment.validate() (lib/models/types/moment.ts:33). This is the warehouse schema type for date fields (e.g. post.date, post.updated). It converts the value to a moment object via toMoment(); if moment.isValid() is false, the value cannot be stored as a date and the save/validate fails.","triggerScenarios":"A post's front-matter date field holds an unparseable value: date: foobar, date: 2021-13-40, date: '' (empty in some flows), or a non-date object/string that moment cannot parse. Also fires on programmatic insert({ date: 'not-a-date' }).","commonSituations":"Hand-edited front-matter with a typo'd date; locale/format mismatch where an expected YYYY-MM-DD is written differently; migrating content with malformed dates; a plugin setting post.date to an invalid string; empty date after a YAML edit.","solutions":["Open the offending post and set date to a valid ISO value: date: 2024-01-15 10:30:00.","If the date is variable, validate it with moment(value).isValid() before assigning.","Search the source for the failing value (the error prints it) and fix every occurrence.","Remove the date field to let Hexo default it rather than storing an invalid one."],"exampleFix":"# before (front-matter)\ndate: 2024-13-40\n\n# after\ndate: 2024-01-15 10:30:00","handlingStrategy":"validation","validationCode":"const moment = require('moment');\nconst m = moment(value);\nif (!m.isValid()) {\n  throw new Error(`Invalid date value: ${JSON.stringify(value)}`);\n}\npost.date = m.toDate();","typeGuard":"const isValidDate = (v: unknown): boolean => {\n  if (v == null) return false;\n  const m = require('moment')(v);\n  return m.isValid();\n};","tryCatchPattern":null,"preventionTips":["Use ISO 8601 dates in front-matter (YYYY-MM-DD HH:mm:ss).","Validate dates before programmatic post insertion.","Lint front-matter dates in a pre-commit hook."],"tags":["model","date","moment","validation","front-matter"],"backgroundTag":null,"analyzedSha":"059cb17494d0632a053c24077f5bcb6ae92acc51","analyzedAt":"2026-08-12T20:52:05.731Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}