@date-fns/utc

UTC-only Date subclasses and a date-fns context helper that eliminate timezone-shift bugs in date arithmetic.

Library
npm
v2.1.1
146stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
34/100Needs Attention
Development Activity12
Maintenance0
Community48
Maturity56
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
61/100Good
Architecture78
Code Quality55
Innovation75
Learning Curve35

@date-fns/utc provides UTCDate and UTCDateMini, drop-in Date subclasses that force every getter, setter, and formatter to operate in Coordinated Universal Time instead of the host system’s local time zone. This removes an entire class of bugs where date-fns calculations silently shift by an hour around Daylight Saving Time transitions, or produce different results depending on where a server or browser happens to be located.

The package also exports a utc context function that plugs directly into date-fns v4’s in option, letting existing date-fns function calls (like isSameDay or addHours) run in UTC without touching how dates are constructed elsewhere in an application. Both classes mirror the native Date API exactly, so migration is typically a drop-in swap for code that already imports Date.

What You Get

  • UTCDate - a full Date-API-compatible class with UTC-based getters, setters, and formatter methods (toString, toLocaleString, and friends).
  • UTCDateMini - a 239-byte minimal variant with only getters, setters, and getTimezoneOffset, for size-sensitive bundles.
  • utc() context helper - a function passed as the in option to date-fns v4 functions so they operate against UTCDate under the hood.
  • Dual ESM/CommonJS publish output with matching TypeScript type declarations (.d.ts and .d.cts) for both module formats.

Common Use Cases

  • Calendar and date-picker rendering, where a given day’s boundaries must not shift when the viewer’s browser timezone differs from the server’s.
  • Server-side date consistency across machines or regions configured with different local timezones.
  • Adopting date-fns v4’s in context option to force UTC semantics across existing function calls without rewriting call sites.
  • Bucketing timestamps into days/weeks for charts and reports without off-by-one-day errors caused by Daylight Saving Time transitions.

Under The Hood

Architecture The package is structured as three sibling modules under src/: date/mini.js defines UTCDateMini extending the native Date, overriding the constructor to route through Date.UTC and replacing every non-UTC-prefixed getter/setter pair via a reflection loop over Date.prototype at module-load time; date/index.js layers UTCDate on top of UTCDateMini, adding only the formatter methods (toString, toLocaleString family) using cached Intl.DateTimeFormat instances pinned to the UTC timezone; utc/index.ts is a thin factory function bridging into date-fns v4’s in context option. The three modules compose through straightforward inheritance and re-export via src/index.ts, keeping the entire runtime surface small enough for aggressive tree-shaking (importing just the mini subpath excludes all formatter code) — the one architectural risk is that correctness depends on iterating Date.prototype’s method names at runtime, coupling behavior to the shape of the host JS engine’s Date implementation.

Tech Stack Authored in a hybrid JS/TS source tree — the class implementations are plain .js files with hand-written companion .d.ts files, while the date-fns context helper is TypeScript — targeting both ESM and CommonJS consumers. The build is Makefile-driven rather than bundler-based: tsc emits declarations, Babel is run twice (BABEL_ENV=esm/cjs) to transpile src/ into .js and .cjs output, and a custom copy script plus a .d.ts-to-.d.cts duplication step assemble the dual-format package. Tests run under Vitest with TZ forced to a non-UTC, non-zero-offset zone to catch timezone leakage, and @sinonjs/fake-timers is a dev dependency used to validate compatibility with mocked clocks. The package declares zero runtime dependencies, keeping its published size trivial.

Code Quality Tests live in colocated tests.ts files (src/date/tests.ts, src/utc/tests.ts) and exercise the full surface of Date getters/setters against known offsets, constructor-argument-count branches, and Sinon fake-timer interop, with several assertions pinned to explicit dates rather than the system clock. Type safety comes from hand-written .d.ts files alongside .js implementations rather than compiling from TypeScript source for the class files, shifting responsibility for keeping types in sync onto the maintainer instead of the compiler. There is a single prettier devDependency but no visible lint step, and no GitHub Actions or other CI workflow files exist in the repository (only a FUNDING.yml under .github/) — correctness relies on manually-run Vitest and an “Are The Types Wrong” packaging check rather than automated CI gating.

API Design The public API is intentionally minimal — two Date subclasses and one context-factory function — with method signatures identical to the native Date API, so the learning curve is close to zero: code that constructs new Date(...) can switch to new UTCDate(...) with no other changes. The utc export composing with date-fns v4’s in option is a considered ergonomic choice, letting consumers opt entire call sites into UTC semantics without wrapping every date value manually. Documentation is concise but complete for a package this size, covering installation and the Mini/full tradeoff with exact byte sizes, though it assumes prior familiarity with date-fns’s context API and doesn’t spell out the package’s tree-shakeable subpath exports in the README itself, requiring a reader to check package.json to discover them.

Used by 10 apps in this directory

TypeScript
76%
AGPL 3.0

Ghostfolio

Invoicing Finance

9,252

Track your stocks, ETFs, and crypto with a privacy-first, self-hostable wealth management platform built for data-driven investors.

View details
93
Repo Health
79
Technical
67
Dependency
Built with
TypeScript76%
HTML21%
Updated yesterday
TypeScript
99%
MIT

GraphQL Hive

Developer Tools · Devops · Monitoring

484

Open-source GraphQL schema registry and observability platform with breaking change detection, federation support, and CI/CD integration for teams of any size.

View details
89
Repo Health
81
Technical
69
Dependency
Built with
TypeScript99%
Updated 2 days ago
TypeScript
72%
Apache 2.0

Litlyx

Analytics

1,740

Cookie-free, AI-powered web analytics you can self-host in 30 seconds with Docker.

View details
45
Repo Health
51
Technical
72
Dependency
Built with
TypeScript72%
Vue26%
Updated 9 months ago
TypeScript
96%
AGPL 3.0

Midday

Invoicing Finance · Productivity

14,958

All-in-one AI-powered business operations platform for freelancers and solo entrepreneurs to manage invoicing, time tracking, banking, and financial intelligence.

View details
55
Repo Health
78
Technical
70
Dependency
Built with
TypeScript96%
Updated 2 months ago
TypeScript
98%
Other

Novu

Developer Tools

39,870

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript98%
Updated yesterday
TypeScript
81%
AGPL 3.0

OpenStatus

Monitoring · Devops

9,072

Open-source status pages and uptime monitoring with global synthetic checks, monitoring-as-code, and AI agent integration via MCP.

View details
77
Repo Health
82
Technical
69
Dependency
Built with
TypeScript81%
MDX15%
Updated yesterday
Python
65%
Apache 2.0

Polar

Ecommerce · Developer Tools · Invoicing Finance

10,240

Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.

View details
90
Repo Health
82
Technical
69
Dependency
Built with
Python65%
TypeScript28%
Updated today
Rust
71%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,116

Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.

View details
86
Repo Health
81
Technical
65
Dependency
Built with
Rust71%
TypeScript25%
Updated yesterday
TypeScript
99%
MIT

Sanity

CMS

6,312

Open-source headless CMS with a fully customizable React Studio, real-time collaborative editing, structured content modeling, and GROQ query language

View details
92
Repo Health
90
Technical
66
Dependency
Built with
TypeScript99%
Updated yesterday

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

Search