.claude/skills/gray-matter-date-gotchas/SKILL.md
Handle gray-matter's automatic Date parsing in YAML frontmatter. Use when: (1) Zod validation fails with "expected string, received Date" on date fields, (2) Building content collection systems with markdown frontmatter, (3) Dates in frontmatter become Date objects instead of strings, (4) Migration/precompile scripts process YAML with date fields. Covers z.preprocess coercion and ensuring dates are written as strings.
npx skillsauth add Dbochman/dotfiles gray-matter-date-gotchasInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
The gray-matter library automatically parses YAML date values as JavaScript Date objects. This breaks validation when using Zod schemas that expect strings, and can cause silent data corruption in migration pipelines.
frontmatter.createdAt instanceof Date returns true unexpectedlyYAML 1.1 (which gray-matter uses) auto-detects dates in these formats:
2026-01-23 (date only)2026-01-23T00:00:00.000Z (ISO 8601)Gray-matter parses these as Date objects, not strings.
Coerce Date objects to ISO strings before validation:
const isoDateString = z.preprocess(
(val) => {
if (val instanceof Date) return val.toISOString();
return val;
},
z.string().refine(
(val) => {
const fullIso = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
const dateOnly = /^\d{4}-\d{2}-\d{2}$/;
return fullIso.test(val) || dateOnly.test(val);
},
{ message: 'Invalid date format. Expected ISO 8601' }
)
);
When writing frontmatter, explicitly convert dates:
function toISOString(value) {
if (!value) return value;
if (value instanceof Date) return value.toISOString();
if (typeof value === 'string') return value;
return String(value);
}
// When building frontmatter object:
frontmatter.createdAt = toISOString(card.createdAt) || new Date().toISOString();
Quoted strings aren't parsed as dates:
createdAt: "2026-01-23T00:00:00.000Z" # String
createdAt: 2026-01-23 # Becomes Date object!
const { data } = matter(content);
console.log(typeof data.createdAt); // Should be 'string'
console.log(data.createdAt); // Should be ISO string, not [object Date]
Before (breaks):
const schema = z.object({
createdAt: z.string() // Fails! gray-matter returns Date
});
After (works):
const schema = z.object({
createdAt: z.preprocess(
(val) => val instanceof Date ? val.toISOString() : val,
z.string()
)
});
development
Search the web for current information, news, facts, and answers. Use when asked questions about current events, needing to look something up, finding websites, researching topics, or when you need up-to-date information beyond your training data.
development
Summarize any URL, YouTube video, podcast, PDF, or file into concise text. Use when asked to read an article, summarize a link, get the gist of a video or podcast, extract content from a URL, or when you need to understand what a web page or document contains.
development
Play music via Spotify and control Google Home speakers. Use when asked to play music, songs, artists, playlists, podcasts, or control speakers/volume/audio.
testing
Create new OpenClaw skills, modify and improve existing skills, and measure skill performance with evals. Use when users want to create a skill from scratch, update or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. Also use when asked to "make a skill", "turn this into a skill", "improve this skill", or "test this skill".