date-fns

Modern JavaScript date utility library with 200+ pure, immutable functions

Library
npm
v4.4.0
36,647 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
78 /100 Good
Development Activity 72
Maintenance 72
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
86 /100 Excellent
Architecture 90
Code Quality 92
Innovation 85
Learning Curve 78

date-fns is a modular, TypeScript-first utility library that provides more than 200 pure functions for parsing, formatting, comparing, and manipulating JavaScript dates. Rather than extending the native Date prototype, every function accepts and returns plain Date instances, keeping behavior predictable and safe to mix with other libraries.

Each function lives in its own submodule, so bundlers can tree-shake unused code and applications only ship the date logic they actually import. The library ships first-class time zone support through companion packages (@date-fns/tz and @date-fns/utc), dozens of locales for internationalized formatting, and an opt-in functional-programming (fp) variant for point-free composition.

What You Get

  • 200+ granular functions (add/sub, compare, diff, format, parse, start/end-of-period, and more), each independently importable
  • First-class, immutable time zone handling via the companion @date-fns/tz (TZDate) and @date-fns/utc (UTCDate) packages
  • Dozens of locale packs for internationalized month/day names, relative-time phrasing, and formatting
  • A functional-programming build (date-fns/fp) with curried, data-last function signatures for composition
  • Full TypeScript definitions generated alongside the source, with generics that preserve custom Date subclasses through the call chain

Common Use Cases

  • Formatting and parsing dates for display in web and Node.js applications
  • Computing durations, differences, and business-day math (e.g. invoice due dates, SLA windows)
  • Normalizing and comparing dates across time zones in scheduling or booking systems
  • Building calendar and date-picker UI components that need start/end-of-period helpers
  • Localizing date and relative-time strings for internationalized products

Under The Hood

Architecture

date-fns is organized as a pnpm monorepo (pkgs/core, pkgs/tz, pkgs/utc, pkgs/docs, pkgs/dev) where the npm date-fns package maps to pkgs/core. Inside pkgs/core/src, each of the 253 exported functions (e.g. addDays, format, differenceInCalendarDays) lives in its own directory with an index.ts implementation and a colocated test.ts, giving the library a flat, highly navigable structure instead of a monolithic module. Cross-cutting behavior is centralized in _lib (formatters, default locale/options, protected-token warnings) and in toDate/constructFrom, which every function routes Date arguments through; constructFrom inspects a Symbol.for("constructDateFrom") on the reference date to decide which constructor to use, which is the mechanism that lets the separate @date-fns/tz (TZDate) and @date-fns/utc (UTCDate) packages plug into the same generic function set without date-fns/core depending on them directly. A parallel src/fp tree (399 files) wraps the same functions in curried, data-last signatures for functional-style composition, and src/locale (98 entries) supplies per-locale formatting data consumed by format/formatDistance at the _lib layer.

Tech Stack

The project is TypeScript-first (96%+ of the codebase) targeting both ESM (index.js) and CJS (index.cjs) output, declared via exports maps with one subpath per function for granular imports and tree-shaking. Tooling is notably modern: oxlint/oxfmt (Rust-based lint/format, replacing ESLint/Prettier) with oxlint-tsgolint for TypeScript-aware linting, @typescript/native-preview (the Go-based tsgo compiler preview), vitest for the test runner, and mise for task/toolchain orchestration in place of npm scripts. The package has zero runtime dependencies, keeping the dependency footprint minimal for consumers. Companion packages @date-fns/tz and @date-fns/utc are versioned and published separately from core within the same monorepo.

Code Quality

Test coverage is essentially 1:1 with the public API: 253 test.ts files sit alongside 253 function implementations in pkgs/core/src, and tests (e.g. addDays/test.ts) cover not just nominal behavior but DST-transition edge cases via a shared getDstTransitions helper and cross-checks against the @date-fns/tz/@date-fns/utc extension types using assertType. Functions are consistently small and single-purpose (most implementation files are well under 50 lines), naming is systematic across the whole API surface (addX/subX, differenceInX, startOfX/endOfX, isX), and every export carries a structured JSDoc block (@summary, @param, @returns, @example) that doubles as the source for the published docs site. Invalid input is handled explicitly and predictably — e.g. addDays short-circuits to NaN-dated output via constructFrom when passed a NaN amount rather than throwing or silently producing a wrong date.

API Design

The API favors small, guessable, single-purpose functions over a chained or class-based interface, which keeps the learning curve shallow for any one function while the sheer surface area (200+ exports) is the main ramp-up cost for the full library. Getting started requires zero boilerplate: import { format } from "date-fns"; format(new Date(), "yyyy-MM-dd") is a complete, working example, and every function’s JSDoc ships a runnable @example. Consistent naming conventions (addX/subX, isX, startOfX) mean that once a developer learns one family of functions, the rest are largely inferable. The optional options?.in context parameter and generic DateType/ResultDate type parameters let advanced users opt into time zone-aware types without imposing that complexity on basic usage, and the separate fp entry point serves functional-style consumers without complicating the default API.

Used by 215 apps in this directory

TypeScript
99%
Other

Teable

Databases · No Code Platforms

21,838

A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.

View details
79
Repo Health
76
Technical
62
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
Go
75%
AGPL 3.0

Teleport

Authentication · Security

20,950

Zero-trust infrastructure access platform that replaces credentials and VPNs with short-lived certificates, SSO, and identity-aware proxies for SSH, Kubernetes, databases, RDP, and AI agents.

View details
93
Repo Health
81
Technical
68
Dependency
Built with
Go 75%
TypeScript 16%
Updated 3 weeks ago
Rust
64%
Apache 2.0

Temps

Analytics · Devops · Monitoring

801

A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.

View details
81
Repo Health
86
Technical
70
Dependency
Built with
Rust 64%
TypeScript 34%
Updated 1 weeks ago
TypeScript
98%
Apache 2.0

Tianji

Analytics · Monitoring

3,100

Replace Google Analytics, UptimeKuma, and Prometheus with one self-hosted platform that tracks websites, monitors uptime, and reports server health.

View details
86
Repo Health
76
Technical
65
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
98%
Apache 2.0

TinaCMS

CMS

13,811

An open-source, Git-backed headless CMS that gives editors a live visual editing UI over Markdown, MDX, JSON, and YAML content while developers keep everything in version control.

View details
92
Repo Health
74
Technical
59
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
73%
AGPL 3.0

Tolaria

Note Taking

19,917

A free, open-source, local-first desktop app for managing markdown knowledge bases on macOS, Windows, and Linux — for second brains, company docs, or AI assistant memory and procedures.

View details
81
Repo Health
71
Technical
68
Dependency
Built with
TypeScript 73%
Rust 13%
JavaScript 12%
Updated 2 weeks ago
TypeScript
56%
Other

Tolgee

Developer Tools

4,115

In-context localization platform that lets developers and translators edit app strings directly in the running application, with AI-powered machine translation and framework SDKs for React, Angular, Vue, and Svelte.

View details
90
Repo Health
84
Technical
65
Dependency
Built with
TypeScript 56%
Kotlin 43%
Updated 2 weeks ago
Python
70%
AGPL 3.0

Tracecat

AI Agents · Automation · Security

3,816

Open-source agentic security automation platform that runs AI agents and durable workflows at scale with sandboxed execution.

View details
89
Repo Health
88
Technical
66
Dependency
Built with
Python 70%
TypeScript 28%
Updated 1 weeks ago
Rust
71%
MIT

Trieve

AI Development · Developer Tools · Search

2,719

All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.

View details
42
Repo Health
74
Technical
64
Dependency
Built with
Rust 71%
Updated 8 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers