Configs2026年5月16日·1 分钟阅读

Luxon — Modern JavaScript Date and Time Library

A powerful immutable date-time library built on the Intl API, created by the Moment.js team as its modern successor.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Luxon Overview
通用 CLI 安装命令
npx tokrepo install b88fe790-50fe-11f1-9bc6-00163e2b0d79

Introduction

Luxon is a modern date-time library for JavaScript that wraps the native Intl API to provide an immutable, chainable interface for parsing, formatting, and manipulating dates across time zones. Built by a core Moment.js maintainer, it addresses Moment's shortcomings — mutability, large bundle size, and limited Intl support.

What Luxon Does

  • Represents dates, times, durations, and intervals as immutable objects with a fluent API
  • Leverages the native Intl API for locale-aware formatting without shipping locale data
  • Handles time zone conversions using IANA zone identifiers without external databases
  • Parses ISO 8601, RFC 2822, HTTP dates, and custom format strings
  • Performs calendar math including DST-safe addition and difference calculations

Architecture Overview

Luxon centers on the DateTime class, which wraps a timestamp and a zone. All operations return new instances rather than mutating state. The library delegates locale formatting and calendar calculations to the runtime Intl.DateTimeFormat and Intl.RelativeTimeFormat APIs, keeping its own code lean. Duration and Interval classes compose naturally with DateTime for range operations.

Self-Hosting & Configuration

  • Install from npm — zero native dependencies, pure JavaScript
  • Import named exports: DateTime, Duration, Interval, Settings, Info
  • Configure default locale and zone globally via Settings.defaultLocale and Settings.defaultZone
  • Tree-shakeable: unused classes do not inflate your bundle
  • Works in Node.js 12+, all modern browsers, Deno, and Bun

Key Features

  • Immutable by design — no accidental date mutations in complex pipelines
  • First-class time zone support via IANA identifiers and fixed UTC offsets
  • Human-friendly duration formatting: Duration.fromMillis(90000).toFormat('m:ss') yields "1:30"
  • Relative time output: dt.toRelative() returns strings like "in 2 hours" using Intl
  • Over 16,000 GitHub stars with widespread adoption as the Moment.js migration path

Comparison with Similar Tools

  • Day.js — smaller bundle with plugin system; Luxon has richer time zone and Intl support built-in
  • Moment.js — mutable and deprecated; Luxon is its official successor with immutable design
  • date-fns — functional tree-shakeable helpers; Luxon offers an object-oriented chainable API
  • Temporal (TC39) — upcoming native API; Luxon works today and shares similar design principles
  • js-joda — port of Java's java.time; Luxon leverages native Intl rather than bundling calendars

FAQ

Q: Should I migrate from Moment.js to Luxon? A: Yes. The Moment team recommends Luxon as a modern replacement. It shares similar concepts but fixes mutability and bundle-size issues.

Q: Does Luxon support non-Gregorian calendars? A: It delegates to Intl, so output formatting respects locale calendars. Internal math is Gregorian-based.

Q: How big is Luxon compared to Day.js? A: Luxon is roughly 20 KB minified+gzipped versus Day.js at 2 KB core, but Luxon includes time zone and Intl support that Day.js requires plugins for.

Q: Can I use Luxon in serverless functions? A: Yes. It has no native dependencies and initializes instantly, making it suitable for cold-start-sensitive environments.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产