JavaScript Temporal API(ジャバスクリプトテンポラルエーピーアイ)
2024年Stage 3+Polyfill普及Temporal API新JavaScript標準。Date代替+Time Zone-aware+Calendar/Duration/Instant/PlainDate型+Moment.js代替+Polyfill経由Production使用可能。
概要
JavaScript Temporal APIは2024年TC39 Stage 3+主要Polyfill(@js-temporal/polyfill)の普及により Production採用可能となったJavaScript標準新Date/Time APIで、JavaScript Date(1995年実装の不完全API)・Moment.js(2011年・現在Maintenance Mode)・date-fns(2016年)・Luxon(2017年)等の歴代Date Libraryを置換する次世代仕様。Date のレガシー問題(Time Zone非対応・Calendar 1種類・Mutable・Type Confusion)を構造的に解決し、Time Zone-aware・Calendar抽象化(Gregorian/Hebrew/Islamic等)・Immutable・Strong Type の4軸で完全な再設計。Calendar/Duration/Instant/PlainDate/PlainDateTime/PlainTime/PlainYearMonth/PlainMonthDay/ZonedDateTime の9種類の型で、用途に応じた厳密な型選択が可能。Stage 3 だが Polyfill 経由でNode.js/Browser両方Production採用可能で、TypeScript型サポートも完備。Browser Native 実装は Firefox 137+(2025年予定)・Chrome/Safari は 2025-2026 年予定。
主な特徴・仕組み
- 9種類の型: Calendar/Duration/Instant/PlainDate/PlainDateTime/PlainTime/PlainYearMonth/PlainMonthDay/ZonedDateTime
- Immutable設計: 全型がImmutable、Mutable Date と決別
- Time Zone-aware: ZonedDateTime/Instant でTime Zone情報明示的に扱う
- Calendar抽象化: Gregorian(西暦)/Hebrew/Islamic/Japanese/Buddhist 等
- Duration型: 期間を独立した型として扱い、加減算が安全
- *Plain 型**: Time Zone なしの型で、Date Object より用途明確
- Static Method 中心:
Temporal.Instant.from()等のStatic Methodベース - ISO 8601対応: 全型 toString() で ISO 8601 形式出力
- TypeScript型サポート: 完全なType Definition、Polyfill経由でも型補完
- Stage 3: TC39最終調整段階、Stage 4(GA)は2025-2026年予想
- Polyfill普及:
@js-temporal/polyfill(Igalia 製、Production-ready)
スペック比較表
| 項目 | Temporal API | JavaScript Date | Moment.js | date-fns | Luxon |
|---|---|---|---|---|---|
| Time Zone-aware | ○ Native | × | ○ Plugin | △ Plugin | ○ Native |
| Calendar抽象化 | ○ 多Calendar | × Gregorian only | × Gregorian | × Gregorian | × Gregorian |
| Immutable | ○ | × Mutable | × Mutable | ○ | ○ |
| Strong Type | ○ 9種型 | × Date のみ | × | △ Type Inference | △ |
| Bundle Size | 0KB(Native時) ~75KB(Polyfill) | 0KB | ~70KB | 13KB+(Tree Shake) | ~76KB |
| Browser Support | Polyfill, Firefox 137+(2025) | 全Browser | 全Browser | 全Browser | 全Browser |
| 学習曲線 | 中-高(9種型) | 低 | 低 | 中 | 中 |
| 最新メンテ | TC39+Igalia | (Built-in) | Maintenance Only | Active | Active |
具体例・対応製品
import { Temporal } from '@js-temporal/polyfill';
// 現在の Instant(UTC)
const now = Temporal.Now.instant();
console.log(now.toString()); // 2026-05-06T05:30:00Z
// ZonedDateTime(Time Zone-aware)
const tokyo = Temporal.Now.zonedDateTimeISO('Asia/Tokyo');
console.log(tokyo.toString()); // 2026-05-06T14:30:00+09:00[Asia/Tokyo]
// PlainDate(日付のみ)
const birthday = Temporal.PlainDate.from('1990-04-15');
const age = birthday.until(Temporal.Now.plainDateISO()).years;
// Duration(期間)
const duration = Temporal.Duration.from({ hours: 2, minutes: 30 });
const future = now.add(duration);
// Calendar変換(Hebrew Calendar)
const hebrew = Temporal.Now.plainDateISO('Asia/Jerusalem')
.withCalendar('hebrew');
console.log(hebrew.year); // 5786(ヘブライ暦)
- @js-temporal/polyfill 0.4.x: Igalia製公式Polyfill、TypeScript完全対応
- Firefox 137+ Native: 2025年予定、Browser Native実装第1号
- TC39 Stage 3: 2024年昇格、Stage 4(GA)は2025-2026年予想
- TypeScript型: lib.dom.d.ts に Temporal 型定義追加(TypeScript 5.7+)
- 競合機種: Moment.js(Maintenance Only)、date-fns(Active)、Luxon(Active)、Day.js(軽量代替)
自作PCでの選び方・注意点
JavaScript Temporal APIはWeb開発者向けの新標準仕様で、jisaku.com Web Frontend(Next.js 16+TypeScript)で重要な技術選択肢。jisaku.com では現在 date-fns 4.x を採用中だが、Temporal API への将来移行を検討すべき技術。Polyfill経由のProduction採用可能性は2024年に確立され、Igalia製 @js-temporal/polyfill はIBM・Bloomberg等の企業で本番運用実績あり。一方、Bundle Size 75KB(Polyfill)は date-fns(13KB+)・Day.js(2KB)・Luxon(76KB)に比べて重量級で、現状はBrowser Native実装待ちが現実的。Firefox 137+(2025年予定)・Chrome/Safari 2025-2026 年Native対応により、2026年末以降に Polyfill不要 + Bundle Size 0KB の理想状態が見込める。Time Zone重視+Calendar抽象化+9種型のStrong Typing は、グローバル展開Webサービス(Multi-region+Multi-locale)で大きなメリット。jisaku.comは日本市場主体だが、海外読者向けにJST/UTC変換+ISO 8601出力で Temporal 価値発揮可能。学習曲線は中-高で、9種型の使い分け(Instant vs ZonedDateTime vs PlainDate等)を理解する必要があり、チーム全体の習熟期間1-2か月見込み。
関連用語との違い
JavaScript Date(1995)との違い: Dateは Mutable+Gregorian only+Time Zone貧弱、Temporalは Immutable+Multi-Calendar+Time Zone-aware。Date は基本的に避けるべきレガシー API、Temporalが将来の標準。 Moment.jsとの違い: Moment.js(2011年)は2020年からMaintenance Onlyで新機能追加なし、推奨は Temporal/date-fns/Luxon。Moment.jsからの移行はTemporal優先、現状ではdate-fnsまたはLuxonも選択肢。
よくある質問(FAQ)
Q1: 既存 date-fns プロジェクトを Temporal に移行すべき? A: 現時点(2026年5月)は急がず。Browser Native実装が Firefox/Chrome/Safari全対応する2027年頃までは date-fns 継続が安全。新規プロジェクトは Temporal から開始するメリットあり、長期的に Bundle Size 削減効果が高い。
Q2: Polyfill のオーバーヘッドは? A: Bundle Size 75KB(gzip 後 ~24KB)、Runtime overhead は Native Date 比 1.5-2倍程度。大半のWebサイトで体感差なし、Hot Path(秒間数千回呼び出し等)では measurable な性能差。Browser Native対応で完全解消。
Q3: 9種類の型の使い分けは? A: 一般的な使い分け: 1)現在時刻+UTC比較 → Instant、2)Time Zone付き日時 → ZonedDateTime、3)誕生日等の日付 → PlainDate、4)アラーム時刻 → PlainTime、5)期間 → Duration、6)曜日不要の年月 → PlainYearMonth、7)誕生日(年除外) → PlainMonthDay。
まとめ
- JavaScript Temporal API = 2024年TC39 Stage 3 + Polyfill Production採用可能
- 9種類のStrong Type(Instant/ZonedDateTime/PlainDate/Duration等)
- Time Zone-aware+Multi-Calendar+Immutable設計
- Date/Moment.js/date-fns/Luxon 全代替候補、ES2025-2026標準化
- Polyfill経由現状利用可能、Browser Native対応2025-2027 年予定