date-fns
date-fns + @date-fns/tz
Purpose
Use this skill to implement, review, and refactor date/time code with modern date-fns and the native timezone package @date-fns/tz.
Version baseline (re-check when invoked)
date-fnslatest verified:4.1.0@date-fns/tzlatest verified:1.4.1- Re-check commands:
npm view date-fns versionnpm view @date-fns/tz versionnpm view date-fns dist-tags --jsonnpm view @date-fns/tz dist-tags --json
When to use
- Parsing, validating, formatting, comparing, and calculating dates.
- Building timezone-aware business logic (scheduling, boundaries, reporting).
- Migrating date logic to immutable utility patterns.
- Hardening code against DST and token-format bugs.
Non-negotiable rules
- Use native timezone package:
@date-fns/tz. - Do not recommend
date-fns-tz. - If legacy code already uses
date-fns-tz, suggest migration to@date-fns/tz. - Parse once, validate early (
isValid), and passDatevalues through operations. - Use Unicode tokens correctly (
yyyy,MM,dd) and avoid Moment-style token assumptions. - For timezone-sensitive calculations, use explicit timezone context (
TZDateor{ in: tz("...") }).
Canonical imports
import { format, parseISO, isValid, addDays, startOfDay } from "date-fns";
import { TZDate, tz, tzOffset, tzName, tzScan } from "@date-fns/tz";
Workflow
1) Normalize input
- Use
parseISO/toDatefor conversion. - Guard with
isValid. - Keep internal values as
Date/TZDate, not mixed string math.
2) Compute with pure helpers
- Prefer
add/sub,differenceIn*,startOf*/endOf*,isSame*,isWithinInterval. - Avoid mutating
Datevia setters unless there is a clear reason.
3) Apply timezone context explicitly
- Option A: use
TZDatevalues. - Option B: use date-fns
inoption withtz("Area/City")for deterministic zone context.
4) Format/output safely
- Use
formatfor display. - Use standards helpers for exchange formats (
formatISO,formatRFC3339). - Keep transport format and display format separate.
Deliverables
When answering, provide:
- Exact imports.
- Minimal correct function set for the use case.
- Timezone strategy (
TZDatevs{ in: tz(...) }) and why. - Edge-case notes (DST boundaries, token correctness, invalid inputs).
Progressive disclosure
Load only what is needed:
reference/core-functions.mdfor essential helpers.reference/native-timezones.mdfor@date-fns/tzpatterns.reference/imports-and-practices.mdfor import/runtime practices.reference/format-parse-tokens.mdfor token correctness.reference/examples.mdfor copy-ready snippets.reference/anti-patterns.mdfor strict "never usedate-fns-tz" guidance.reference/version-and-sources.mdfor version checks and source links.
More from wottpal/skills
jotai-nextjs
Expert workflow for Jotai state management with a Next.js focus, covering core APIs, SSR hydration, utilities, recipes, and current release migrations.
10use-the-index-luke
Postgres query and index optimization workflow based on use-the-index-luke principles. Use for EXPLAIN analysis, index design, predicate rewrites, joins, sorting, and pagination tuning.
8deep-research-firecrawl
Conducts citation-backed research using Firecrawl MCP search, scrape, map, crawl, and agent tools with selectable quick, standard, deep, and ultradeep modes. Use for multi-source comparisons, technical evaluations, market research, and high-stakes decision support.
8readme-agents-writer
Build and maintain unified README.md + AGENTS.md + CLAUDE.md docs where symlink-triplet policy is strict, and the canonical README remains an in-depth, high-signal agent instruction and engineering playbook.
6slack-web-api
Use when you need to read or act on Slack data via the Slack Web API (post messages, search, list channels, fetch channel history/threads, add/remove reactions). Provides a Bun+TypeScript CLI wrapper around @slack/web-api for deterministic queries and structured JSON output.
4worktree-handoff
Safely hand off the current source worktree state, including untracked files, onto a local target branch (default `develop`) without modifying the source worktree, using an alternate-index snapshot and target-side cherry-pick.
2