jobmetric/multi-calendar
Composer 安装命令:
composer require jobmetric/multi-calendar
包简介
Multi-Calendar is a PHP library for converting dates between Gregorian, Jalali, Hijri, Hebrew, Buddhist, Coptic, Ethiopian, and Chinese calendars, with simple API and support for array or formatted string outputs.
README 文档
README
Multi Calendar for PHP
Multi-Calendar is a PHP library for converting dates between multiple calendar systems, including Gregorian, Jalali (Persian), Hijri (Islamic), Hebrew, Buddhist, Coptic, Ethiopian, and Chinese. It provides an easy-to-use API with support for both array and formatted string outputs, making date conversions reliable and consistent across different calendar types.
Install via composer
Run the following command to pull in the latest version:
composer require jobmetric/multi-calendar
Documentation
Basic Usage
use JobMetric\MultiCalendar\Converters\JalaliConverter; use JobMetric\MultiCalendar\Converters\HijriConverter; // Jalali (Persian) Example $jalali = new JalaliConverter(); $result = $jalali->fromGregorian(2025, 8, 13); // [1404, 5, 22] echo implode('/', $result); // "1404/05/22" $gregorian = $jalali->toGregorian(1404, 5, 22); // [2025, 8, 13] echo implode('-', $gregorian); // "2025-08-13" // Hijri Example $hijri = new HijriConverter(); echo $hijri->fromGregorian(2025, 8, 13, '/'); // e.g. "1447/02/20"
Supported Calendars
This library supports the following calendar systems, each with its own converter class. You can instantiate these classes and use their methods to convert dates between the Gregorian calendar and the respective calendar system.
| Calendar Key | Class Name | Description |
|---|---|---|
gregorian |
GregorianConverter (default) | The standard calendar used worldwide. |
jalali (Persian) |
JalaliConverter | The Iranian calendar, also known as the Solar Hijri calendar. |
hijri (Islamic) |
HijriConverter | The lunar calendar used in the Islamic world. |
hebrew |
HebrewConverter | The calendar used in Jewish culture. |
buddhist |
BuddhistConverter | The calendar used in many Buddhist countries. |
coptic |
CopticConverter | The calendar used in the Coptic Orthodox Church. |
ethiopian |
EthiopianConverter | The calendar used in Ethiopia. |
chinese |
ChineseConverter | The traditional Chinese calendar. |
Using the Factory
You can also use the CalendarConverterFactory to create converters dynamically based on the calendar key:
use JobMetric\MultiCalendar\Factory\CalendarConverterFactory; // Create a converter dynamically $conv = CalendarConverterFactory::make('jalali'); // Convert Gregorian to Jalali echo $conv->fromGregorian(2025, 8, 13, '/'); // "1404/05/22"
Number Transliteration
You can convert numbers between English, Persian, and Arabic numeral systems:
use JobMetric\MultiCalendar\Helpers\NumberTransliterator; echo NumberTransliterator::trNum('2025/08/13', 'fa'); // "۲۰۲۵/۰۸/۱۳" echo NumberTransliterator::trNum('۱۴۰۴/۰۵/۲۲', 'en'); // "1404/05/22"
Output Format
Array output: default when $mod (separator) is empty
Example: [2025, 8, 13]
String output: set $mod to a separator (/, -, .)
Example: "2025/08/13"
Example Conversion Table for 2025-08-13 (Gregorian)
| Calendar | Date |
|---|---|
| Gregorian | 2025-08-13 |
| Jalali | 1404-05-22 |
| Hijri | 1447-02-20 |
| Hebrew | 5785-12-19 |
| Buddhist | 2568-08-13 |
| Coptic | 1741-12-07 |
| Ethiopian | 2017-12-07 |
| Chinese | 2025-07-11 |
Note: Values for non-Gregorian calendars are calculated using the
intlextension. Actual results may vary slightly based on leap year and leap month handling.
Command Line Tool
The package includes a command-line tool (date-converter.sh) that allows you to convert dates between different calendar systems directly from your terminal without writing PHP code.
Usage
You can use the command-line tool in two ways:
Direct execution:
date-converter.sh [date] [options]
Using Composer alias:
composer date-convert -- [date] [options]
Note: When using the Composer alias, use
--to separate Composer arguments from the script arguments.
Arguments
| Argument | Description |
|---|---|
date |
Optional. If not provided, current date (now) will be used. |
Options
| Option | Short | Description | Default |
|---|---|---|---|
--date-format |
-df |
Input calendar type (supported calendar systems) | gregorian |
--to |
-t |
Output calendar type (supported calendar systems) | gregorian |
--format-input |
-fi |
Input date string format (supported date formats), auto-detected if not provided | Auto-detect |
--format-output |
-fo |
Output date format (supported date formats) | Y-m-d |
--timezone |
-tz |
Convert time to specified timezone (e.g., Asia/Tehran, UTC, Europe/London) | None |
--from-timezone |
-ftz |
Source timezone for time conversion (e.g., UTC, Europe/London) | Auto-detect |
--to-timezone |
-ttz |
Target timezone for time conversion (e.g., Asia/Tehran, UTC) | None |
--help |
-h |
Show this help message | - |
Supported Calendar Systems
gregorianjalaliorpersianhijriorislamichebrewbuddhistcopticethiopianorethiopicchinese
Supported Date Formats
Y-m-dd/m/YF d YY/m/d H:i:s(with time)
Timezone Conversion
The command-line tool supports timezone conversion in two ways:
-
Simple timezone conversion (using
--timezonefor backward compatibility):- Converts the input time to the specified timezone
- Automatically detects the source timezone from the input date or uses default based on calendar type
-
Explicit timezone conversion (using
--from-timezoneand--to-timezone):- Allows you to explicitly specify both source and target timezones
- More precise control over timezone conversion
- Automatically adds time to output format if timezone conversion is performed
Important Notes:
- When timezone conversion is performed and the input contains time, the output format will automatically include time (
H:i:s) if not already specified - If no time is present in the input, timezone conversion will not add time to the output
- Supported timezone formats: All PHP supported timezone identifiers (e.g.,
UTC,Asia/Tehran,Europe/London,America/New_York,Asia/Kabul,America/Sao_Paulo)
Timezone Conversion Examples:
# Convert from UTC to Asia/Tehran # Input: 2025-12-20 12:00:00 (UTC) # Output: 2025/12/20 15:30:00 (Asia/Tehran, UTC+3:30) date-converter.sh "2025-12-20 12:00:00" --from-timezone UTC --to-timezone Asia/Tehran # Convert from Europe/London to Asia/Kabul # Input: 2025-12-20 12:00:00 (London, UTC+0 in winter) # Output: 2025/12/20 16:30:00 (Kabul, UTC+4:30) date-converter.sh "2025-12-20 12:00:00" --from-timezone Europe/London --to-timezone Asia/Kabul # Convert from America/Sao_Paulo to Asia/Tehran # Input: 2025-12-20 12:00:00 (Brazil, UTC-3) # Output: 2025/12/20 18:30:00 (Tehran, UTC+3:30) date-converter.sh "2025-12-20 12:00:00" --from-timezone America/Sao_Paulo --to-timezone Asia/Tehran # Convert calendar and timezone together (Gregorian to Jalali with timezone conversion) # Input: 2025-12-20 12:00:00 (UTC) # Output: 1404/09/29 15:30:00 (Jalali calendar, Asia/Tehran timezone) date-converter.sh "2025-12-20 12:00:00" --to jalali --from-timezone UTC --to-timezone Asia/Tehran # Convert calendar and timezone (Jalali to Gregorian with timezone conversion) # Input: 1404-09-29 15:30:00 (Jalali, Asia/Tehran) # Output: 2025/12/20 12:00:00 (Gregorian, UTC) date-converter.sh "1404-09-29 15:30:00" --date-format jalali --to gregorian --from-timezone Asia/Tehran --to-timezone UTC
Examples
Direct execution:
# Convert Gregorian to Jalali date-converter.sh "2025-12-20" --to jalali --format-output Y/m/d # Convert Jalali to Gregorian date-converter.sh "1403-10-01" --date-format jalali --to gregorian # Convert with custom input format date-converter.sh "20/12/2025" --format-input "d/m/Y" --to jalali # Convert with timezone (backward compatibility) date-converter.sh "2025-12-20 12:00:00" --timezone Asia/Tehran # Convert timezone from one timezone to another date-converter.sh "2025-12-20 12:00:00" --from-timezone UTC --to-timezone Asia/Tehran --format-output "Y/m/d H:i:s" # Convert timezone from London to Afghanistan date-converter.sh "2025-12-20 12:00:00" --from-timezone Europe/London --to-timezone Asia/Kabul --format-output "Y/m/d H:i:s" # Convert timezone from Brazil to Tehran date-converter.sh "2025-12-20 12:00:00" --from-timezone America/Sao_Paulo --to-timezone Asia/Tehran --format-output "Y/m/d H:i:s" # Convert calendar and timezone together (Gregorian to Jalali with timezone conversion) date-converter.sh "2025-12-20 12:00:00" --to jalali --from-timezone UTC --to-timezone Asia/Tehran --format-output "Y/m/d H:i:s" # Convert calendar and timezone (Jalali to Gregorian with timezone conversion) date-converter.sh "1404-09-29 15:30:00" --date-format jalali --to gregorian --from-timezone Asia/Tehran --to-timezone UTC --format-output "Y/m/d H:i:s"
Using Composer alias:
# Convert Gregorian to Jalali composer date-convert -- "2025-12-20" --to jalali --format-output Y/m/d # Convert Jalali to Gregorian composer date-convert -- "1403-10-01" --date-format jalali --to gregorian # Convert with custom input format composer date-convert -- "20/12/2025" --format-input "d/m/Y" --to jalali # Convert timezone (backward compatibility) composer date-convert -- "2025-12-20 12:00:00" --timezone Asia/Tehran # Convert timezone from UTC to Asia/Tehran composer date-convert -- "2025-12-20 12:00:00" --from-timezone UTC --to-timezone Asia/Tehran --format-output "Y/m/d H:i:s" # Convert timezone from London to Afghanistan composer date-convert -- "2025-12-20 12:00:00" --from-timezone Europe/London --to-timezone Asia/Kabul --format-output "Y/m/d H:i:s" # Convert timezone from Brazil to Tehran composer date-convert -- "2025-12-20 12:00:00" --from-timezone America/Sao_Paulo --to-timezone Asia/Tehran --format-output "Y/m/d H:i:s" # Convert calendar and timezone together composer date-convert -- "2025-12-20 12:00:00" --to jalali --from-timezone UTC --to-timezone Asia/Tehran --format-output "Y/m/d H:i:s"
License
The MIT License (MIT). Please see License File for more information.
Contributing
Thank you for considering contributing to the Laravel Multi Calendar! The contribution guide can be found in the CONTRIBUTING.md.
jobmetric/multi-calendar 适用场景与选型建议
jobmetric/multi-calendar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 244 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「calendar」 「laravel」 「jobmetric」 「date-formatting」 「multi-calendar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jobmetric/multi-calendar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jobmetric/multi-calendar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jobmetric/multi-calendar 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A modern PHP library for generating iCalendar v2.0 events
A powerful event calendar Tool for Laravel's Nova 5.
Check for holidays - localeaware
This TYPO3 distribution provides a sample website using bootstrap and the extensions pizpalue and container_elements. The distribution tailors Swiss market featuring German as default language and additional translations to French, English and Finnish.
Simple ASCII output of array data
统计信息
- 总下载量: 244
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 30
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-14