Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Jalali Dates in Modern PHP: Building ParsiDate — Immutable, Zero-Dependency, with Holidays Built In

说明与用途

ParsiDate 是一个 PHP 库,用于处理 Jalali 日期,提供不可变性、零依赖、内置节假日数据、波斯数字支持和伊斯兰历转换。

问题

Developers building software for Persian speakers need reliable Jalali (Solar Hijri) dates in PHP, but existing libraries are outdated, mutable, or require maintenance of holiday lists.

结果

ParsiDate offers immutable date objects, zero dependencies, built‑in holiday data, Persian digit support, and Hijri conversion, simplifying Jalali date handling in PHP projects.

工作流

  • Install via Composer: composer require mahdyaralipor/parsidate
  • Create a date: $date = ParsiDate::create(1403,1,1);
  • Add days immutably: $later = $date->addDays(10);
  • Check holidays: $date->isHoliday(); $date->holidayName();
  • Add workdays skipping Fridays and holidays: $date->addWorkdays(5);
  • Iterate periods: $period = ParsiPeriod::ofMonth(1403,1); foreach($period->fridays() as $friday){ echo $friday->format('Y/m/d'); }
  • Parse Persian digits: ParsiDate::parse('۱۴۰۳/۰۶/۱۵');
  • Convert to Hijri: $date->toHijri();

证据

If you build software for 85+ million Persian speakers, you need Jalali (Solar Hijri) dates.

来源

I built ParsiDate to fix that for my own projects. It's now at v1.1.0, MIT licensed, with 136 passing tests:

来源

  1. Immutable by default. Every arithmetic method returns a new instance:

来源

  1. Zero dependencies. composer.json requires exactly one thing: php: ^8.1. No Carbon, no framework, no polyfills.

来源

  1. Holidays are data, not your problem. Official Iranian public holidays (1400–1406, verified date-by-date against the official calendar) ship inside the package, with an API for variable holidays:

来源

  1. Persian digits everywhere. Parsing and formatting both understand ۰۱۲۳۴۵۶۷۸۹, because real user input uses them:

来源

  • 记录日期: 2026-10-06T12:41:16.739Z