eram/daynum
最新稳定版本:v1.0.0-beta.1
Composer 安装命令:
composer require eram/daynum
包简介
Immutable, zero-runtime-dependency multi-calendar library for PHP 8.1+. Gregorian, Jalali (Shamsi), and Hijri, differentially tested against ICU.
关键字:
README 文档
README
Immutable, zero-runtime-dependency, multi-calendar PHP library.
Daynum is a clean, single-package replacement for the 3–4 libraries PHP developers currently glue together to get Gregorian + Jalali (Shamsi) + Hijri support. It targets PHP 8.1+, requires no ext-intl at runtime, pulls no transitive dependencies, and is differentially tested against ICU on ~220,000 dates per calendar per CI build.
v1 ships Gregorian, Jalali, and Hijri (Saudi Umm al-Qura + tabular civil), with English, Persian, and Arabic locales.
What Daynum is (and isn't)
Daynum IS: multi-calendar date conversion + formatting, immutable arithmetic, locale-aware formatting with PHP date() tokens, a zero-dependency ICU-tested replacement for morilog/jalali.
Daynum is NOT: a timezone library (use toDateTimeImmutable() for DST math), a relative-date parser ("next Monday"), a Carbon replacement (Carbon covers Gregorian + timezones; Daynum covers multi-calendar + correctness), or a framework bridge.
Naming caveat:
Instantis civil, not UTC. Unlikejava.time.Instant, Daynum'sInstantis a calendar-neutral civil datetime:(JDN, time-of-day, timezone label). Two instants with the same JDN and time but different tzLabels represent different physical moments. See docs/en/concepts.md.
| Feature | Daynum | Carbon | morilog/jalali | ext-intl |
|---|---|---|---|---|
| Jalali | Birashk 33-year | No | Birashk (same) | Borkowski |
| Hijri UAQ | Bundled table | No | No | Runtime ICU |
| Hijri Civil | Yes | No | No | Yes |
| Runtime deps | Zero | symfony/* | nesbot/carbon | ext-intl |
| Immutable | Yes | Optional | No | N/A |
| Testing | ICU differential | Unit tests | Unit tests | IS the oracle |
Install
composer require eram/daynum:^1.0@beta
Quick start
use Eram\Daynum\Instant; use Eram\Daynum\Calendar\Jalali\JalaliView; // Construction — one calendar to pick from, three calendars to read back $d = Instant::fromGregorian(2026, 4, 8, 14, 30, 0, 'Asia/Tehran'); $d->gregorian()->format('Y-m-d'); // "2026-04-08" $d->jalali()->format('Y/m/d'); // "1405/01/19" $d->hijri()->format('j F Y'); // "21 Shawwal 1447" // Persian locale + Persian digits $d->jalali()->withLocale('fa')->withDigits('persian')->format('l j F Y'); // "چهارشنبه ۱۹ فروردین ۱۴۰۵" // Immutable arithmetic — returns Instant, re-enter a view to format $next = $d->jalali()->addMonths(1); // Instant $next->jalali()->format('Y/m/d'); // "1405/02/19" // Strict parsing — digits in any script are normalized JalaliView::parseExact('۱۴۰۵/۰۱/۱۹', 'Y/m/d'); // Instant JalaliView::tryParseExact('nope', 'Y/m/d'); // null // JSON round-trip contract json_encode($d); // {"jdn":2461139,"secondsOfDay":52200,"tzLabel":"Asia/Tehran"} Instant::fromArray(json_decode(json_encode($d), true))->equals($d); // true // Escape hatch to native PHP for real timezone math $d->toDateTimeImmutable();
Documentation
Learn
- Getting Started — install, first example, 5-minute tour
- Concepts — civil vs. UTC,
Instantvs. view, JDN, immutability - Cookbook — 10+ task-indexed recipes
- FAQ — surprising-but-intentional design decisions
Calendars
Reference
- API Reference — every type and method
- Formatting · Parsing · Arithmetic
- Localization · Timezones · Exceptions · Serialization
Migration & attribution
Contributing
Bug reports, docs fixes, new locales, and new calendar systems are welcome. See CONTRIBUTING.md for testing, fixture regeneration, and the "how to add a new calendar" checklist.
Links
- CHANGELOG.md — release notes
- LICENSE — MIT
- Issue tracker
License
MIT. See LICENSE.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-12