Moment.js

Parse, validate, manipulate, and display dates in JavaScript with a chainable API.

Library
npm
v2.31.0
47,885 stars
MIT License

Repository Health

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

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
69 /100 Good
Architecture 68
Code Quality 72
Innovation 55
Learning Curve 80

Moment.js is a battle-tested JavaScript library for parsing, validating, manipulating, and formatting dates and times. It normalizes ISO 8601 strings, RFC 2822 strings, arrays, plain objects, and native Date instances into a single chainable Moment object, then exposes getters, setters, arithmetic (add/subtract/diff), and locale-aware formatting through one consistent API.

Originally released in 2011, Moment became the de facto standard for date handling in the JavaScript ecosystem for nearly a decade, and ships with 137 bundled locale files for out-of-the-box internationalized output. The project is now in maintenance mode — the maintainers explicitly recommend newer, immutable, tree-shakeable alternatives for new projects — but Moment remains widely deployed in legacy codebases and is still the most immediately recognizable name in JS date handling.

What You Get

  • A single moment() factory that parses ISO 8601, RFC 2822, arrays, plain objects, or custom format strings into one consistent Moment instance
  • A chainable API for arithmetic and queries — .add(), .subtract(), .diff(), .startOf(), .isBefore(), .isSame() — that all compose on the same object
  • 137 bundled locale files for out-of-the-box internationalized month names, weekday names, and relative-time phrasing
  • Flexible, token-based formatting and parsing (.format(‘YYYY-MM-DD’), custom token strings) with strict-mode parsing for validation
  • Duration support (moment.duration()) for representing and formatting spans of time independent of a fixed calendar date
  • UMD packaging that works via CommonJS require, AMD, or a plain <script> global, plus hand-maintained TypeScript typings

Common Use Cases

  • Formatting and displaying dates in a user’s locale in legacy server-rendered or jQuery-era frontends
  • Parsing loosely-formatted date strings from forms, CSV imports, or third-party APIs into a validated Date
  • Computing relative time (‘3 hours ago’) and human-readable durations for activity feeds and timestamps
  • Date arithmetic in Node.js backends — adding business days, computing age, or generating date ranges for reports
  • Maintaining and extending older codebases that already depend on Moment where a migration to a newer library isn’t yet planned

Under The Hood

Architecture

Moment wraps the native JavaScript Date object behind a single moment() factory function exported from src/lib/moment/moment.js, with construction logic split across src/lib/create/ (from-string.js, from-array.js, from-string-and-format.js, from-object.js) that normalizes any input — ISO strings, RFC 2822 strings, arrays, plain objects, other Moment instances, or a format string — into an internal _d Date plus a set of parsing-flag diagnostics from parsing-flags.js. Once constructed, a Moment instance exposes a large chainable prototype (src/lib/moment/prototype.js) whose getters/setters (src/lib/units/*.js, one file per unit: year.js, month.js, day-of-month.js, etc.) read and write through a shared set-tokens helper so operations like .add(), .subtract(), .startOf(), and .diff() all funnel through the same duration and unit-offset primitives in src/lib/duration/. Formatting output runs the inverse of parsing: src/lib/format/format.js tokenizes a format string once and caches the token array, then src/lib/locale/ (137 locale files) supplies the token-to-string tables consumed at format time, giving locale-aware output without touching Intl.

Tech Stack

The library ships as hand-written, dependency-free ES5-compatible JavaScript (package.json has zero runtime dependencies) authored in an ES module style under src/ and built to a single UMD bundle (moment.js at the repo root, dist/moment.js) via a Grunt + Rollup pipeline (Gruntfile.js, grunt-contrib-concat/uglify tasks) so it can be required from CommonJS, loaded via AMD, or dropped in as a global <script> tag. TypeScript typings are maintained by hand in moment.d.ts and mirrored for older TypeScript versions under ts3.1-typings/, rather than generated from source. Dev tooling is ESLint (eslint:recommended, ES6 module parsing) plus Prettier for formatting, and the test/build scripts are orchestrated entirely through Grunt rather than a modern bundler like Vite or esbuild — a reflection of the project’s age (created 2011).

Code Quality

Test coverage is substantial: 193 files under src/test/ (split into src/test/moment/, src/test/locale/, and src/test/helpers/) run on QUnit via Karma across multiple browser launchers (Chrome, Firefox, Sauce Labs), covering both core API behavior and per-locale formatting edge cases. Source files are small and single-purpose (e.g. src/lib/create/from-string-and-format.js at ~140 lines handles only ISO/RFC2822/custom-format parsing dispatch), which keeps individual units easy to reason about even though the overall API surface is large. Naming is consistent and low-abstraction (plain function exports, no classes), matching the codebase’s 2011-era JavaScript style, and ESLint’s eslint:recommended ruleset is enforced in CI. The main caveat found in the README itself: the project is explicitly in maintenance mode (‘Moment.js is a legacy project… In most cases, you should choose a different library’), so code quality is stable but not actively hardened against new edge cases.

API Design

Moment’s signature strength is a fluent, chainable API — moment().add(1, ‘day’).format(‘YYYY-MM-DD’) — that made it the default JS date library for a decade, and that ergonomic pattern is still widely imitated by successor libraries. Getting started requires no configuration: import moment, call moment() or moment(‘2024-01-01’), and every mutation/query method returns a Moment or primitive without extra boilerplate. The cost is a large, sometimes overlapping method surface (multiple ways to parse the same input, mutable-by-default instances that trip up developers expecting immutability) and a mutable object model that the library’s own docs now steer newcomers away from in favor of immutable alternatives. Documentation at momentjs.com/docs is thorough and example-driven, and the maintainers’ ‘Project Status’ page is unusually candid about the library’s limitations and recommended alternatives.

Used by 63 apps in this directory

TypeScript
39%
AGPL 3.0

OpenObserve

Analytics · Devops · Monitoring

22,475

Open source observability platform for logs, metrics, traces, and real user monitoring — delivering 140x lower storage costs than Elasticsearch with a single binary you can run in under 2 minutes.

View details
90
Repo Health
9
Technical
68
Dependency
Built with
TypeScript 39%
Rust 30%
Vue 17%
Updated 6 days ago
Ruby
78%
GPL 3.0

OpenProject

Collaboration · Productivity · Project Management

16,598

The open source project management platform that unifies Gantt charts, agile boards, time tracking, and team collaboration under full self-hosted control.

View details
96
Repo Health
79
Technical
69
Dependency
Built with
Ruby 78%
TypeScript 14%
Updated 6 days ago
JavaScript
90%
Other

OpenSign

Digital Signiture

7,163

Self-host a full-featured DocuSign alternative with unlimited e-signatures, multi-signer workflows, and cryptographic PDF signing.

View details
83
Repo Health
61
Technical
69
Dependency
Built with
JavaScript 90%
Updated 1 weeks ago
Vue
41%
AGPL 3.0

Operational

Analytics · Automation · Monitoring

474

Open-source event tracker with real-time push notifications and action buttons for tech founders.

View details
54
Repo Health
68
Technical
68
Dependency
Built with
Vue 41%
JavaScript 39%
MDX 13%
Updated 4 weeks ago
JavaScript
64%
AGPL 3.0

overleaf

Collaboration · Productivity

18,266

Open-source, real-time collaborative LaTeX editor with sandboxed compilation and full TeXLive support for self-hosted academic and research teams.

View details
84
Repo Health
80
Technical
59
Dependency
Built with
JavaScript 64%
TypeScript 30%
Updated 1 months ago
TypeScript
99%
AGPL 3.0

Pangolin

Networking

23,187

An open-source, identity-based zero-trust remote access platform built on WireGuard — a self-hostable alternative to Cloudflare Tunnel and Twingate with SSO, OIDC, and tunneled reverse proxying.

View details
87
Repo Health
68
Technical
68
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
Go
82%
AGPL 3.0

PeerDB

Data Engineering · Databases

3,309

Postgres-native ETL that streams change data capture in real time to Snowflake, BigQuery, ClickHouse, S3, and Kafka — up to 10x faster than general-purpose pipelines, managed through a familiar Postgres SQL interface.

View details
89
Repo Health
76
Technical
66
Dependency
Built with
Go 82%
TypeScript 12%
Updated 6 days ago
TypeScript
96%
Apache 2.0

Pezzo

AI Development · Monitoring

3,278

Open-source LLMOps platform for prompt management, AI observability, intelligent caching, and real-time cost tracking across LLM providers.

View details
59
Repo Health
75
Technical
66
Dependency
Built with
TypeScript 96%
Updated 2 months ago
TypeScript
90%
MIT

Plasmic

CMS · Design Tools · Low Code Platforms

7,125

The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.

View details
81
Repo Health
78
Technical
64
Dependency
Built with
TypeScript 90%
Updated 1 weeks 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