asorasoft/chhankitek
Composer 安装命令:
composer require asorasoft/chhankitek
包简介
Convert from AD (Anno Domini) to Lunar (Chhankitek) format.
关键字:
README 文档
README
Chhankitek for Laravel
A PHP package to convert dates to Lunar (Chhankitek) format — works with or without Laravel. Learn more about Khmer calendar.
🇰🇭 Stand with Cambodia • កម្ពុជា
🕊️ Cambodia Needs Peace 🕊️
We stand in solidarity with our brave soldiers defending Cambodia's sovereignty and territorial integrity. Our hearts are with those protecting our homeland during these challenging times. We call upon the international community to support peaceful resolution and respect for Cambodia's borders.
🙏 កម្ពុជាត្រូវការសន្តិភាព • Together we stand for peace and sovereignty
Documentation
For detailed documentation, please visit https://chhankitek.netlify.app
Installation
You can install the package via composer:
composer require asorasoft/chhankitek
Usage
// In your Laravel controller, use this trait use HasChhankitek; // Convert a date to lunar format $toLunarDate = $this->chhankitek(Carbon\CarbonImmutable::now()->setTimezone('Asia/Phnom_Penh')); $toLunarDate->toString(); // ថ្ងៃច័ន្ទ ៤ រោច ខែបឋមាសាឍ ឆ្នាំឆ្លូវ ត្រីស័ក ពុទ្ធសករាជ ២៥៦៥
Timezone note:
->setTimezone('Asia/Phnom_Penh')ensures the correct Cambodian date is used when your server runs in a different timezone (e.g. UTC). Near midnight UTC, the calendar date differs from Cambodia's. You can omit it ifapp.timezoneinconfig/app.phpis already set toAsia/Phnom_Penh.
Available Methods
// In your Laravel controller, use this trait use HasChhankitek; $toLunarDate = $this->chhankitek(Carbon\CarbonImmutable::now()->setTimezone('Asia/Phnom_Penh')); // see timezone note above // Get specific lunar date components $toLunarDate->getDayOfWeek(); // អាទិត្យ, ច័ន្ទ... $toLunarDate->getLunarDay(); // ១កើត, ២កើត... $toLunarDate->getLunarMonth(); // ចេត្រ... $toLunarDate->getLunarZodiac(); // ជូត, ឆ្លូវ... $toLunarDate->getLunarEra(); // ត្រីស័ក... $toLunarDate->getLunarYear(); // ២៥៦៥, ២៥៦៦..
Alternatively, you can use the toLunarDate helper function:
toLunarDate(Carbon\CarbonImmutable::now()->setTimezone('Asia/Phnom_Penh')); // ថ្ងៃច័ន្ទ ៤ រោច ខែបឋមាសាឍ ឆ្នាំឆ្លូវ ត្រីស័ក ពុទ្ធសករាជ ២៥៦៥
Pure PHP Usage (without Laravel)
The package works in any PHP project — Laravel is not required. The only runtime dependency is nesbot/carbon.
composer require asorasoft/chhankitek
Instantiate Chhankitek directly and read the lunar date from the formatKhmerDate property:
require 'vendor/autoload.php'; use Asorasoft\Chhankitek\Chhankitek; use Carbon\CarbonImmutable; $target = CarbonImmutable::now()->setTimezone('Asia/Phnom_Penh'); $toLunarDate = (new Chhankitek($target))->formatKhmerDate; $toLunarDate->toString(); // ថ្ងៃច័ន្ទ ៤ រោច ខែបឋមាសាឍ ឆ្នាំឆ្លូវ ត្រីស័ក ពុទ្ធសករាជ ២៥៦៥ $toLunarDate->getLunarMonth(); // ចេត្រ... $toLunarDate->getLunarYear(); // ២៥៦៥...
The toLunarDate() helper is also available outside Laravel:
toLunarDate(CarbonImmutable::now()->setTimezone('Asia/Phnom_Penh'));
Khmer Numerals
Convert Arabic numerals to their Khmer representation with the HasKhmerNumberConversion trait:
use Asorasoft\Chhankitek\Traits\HasKhmerNumberConversion; class SomeController { use HasKhmerNumberConversion; public function index() { $this->convertToKhmerNumber(2569); // ២៥៦៩ $this->convertToKhmerNumber('2025-05-11'); // ២០២៥-០៥-១១ } }
Caching
The package caches converted dates for one year (365 days) to minimize computational overhead for frequently accessed dates. The cache is swappable via the CacheRepository interface, so it works the same whether or not you use Laravel.
Default behavior
- Inside Laravel — automatically uses Laravel's cache system (
LaravelCache), so it respects whatever cache driver your application is configured with. No setup required. - Pure PHP — falls back to an in-memory cache (
ArrayCache) that de-duplicates lookups within a single request or script run.
Providing your own cache
Pass any implementation of Asorasoft\Chhankitek\Cache\CacheRepository as the second constructor argument:
use Asorasoft\Chhankitek\Cache\ArrayCache; use Asorasoft\Chhankitek\Cache\CacheRepository; use Asorasoft\Chhankitek\Chhankitek; use Carbon\CarbonImmutable; // Use the bundled in-memory cache explicitly $toLunarDate = (new Chhankitek($target, new ArrayCache))->formatKhmerDate; // Or wire up your own (e.g. a PSR-16 adapter) final class Psr16Cache implements CacheRepository { public function __construct(private \Psr\SimpleCache\CacheInterface $cache) {} public function remember(string $key, int $ttl, callable $callback): mixed { if ($this->cache->has($key)) { return $this->cache->get($key); } $value = $callback(); $this->cache->set($key, $value, $ttl); return $value; } } $toLunarDate = (new Chhankitek($target, new Psr16Cache($yourCache)))->formatKhmerDate;
Testing
composer test
The test suite is split into two groups — run them individually if needed:
vendor/bin/pest --testsuite=PurePhp # framework-free tests (no Laravel) vendor/bin/pest --testsuite=Laravel # Laravel integration tests
Changelog
Please see CHANGELOG for more information about recent changes.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email mabhelitc@gmail.com instead of using the issue tracker.
Support
If you like this package and want to support me, you can buy me a coffee ☕
Credits
License
The MIT License (MIT). Please see License File for more information.
Authors and Acknowledgment
This library would not exist without the hard work of these people:
- Based on the algorithm by
Mr. Phylypo Tumfrom Khmer Calendar - Ported from momentkh by
ThyrithSorintoJava - Khmer New Year Time Calculation
- Ported from MetheaX/khmer-chhankitek-calendar by
MetheaXinto aLaravel Package
asorasoft/chhankitek 适用场景与选型建议
asorasoft/chhankitek 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.13k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2021 年 06 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「asorasoft」 「chhankitek」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 asorasoft/chhankitek 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 asorasoft/chhankitek 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 asorasoft/chhankitek 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 5.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-27