A Laravel package to convert dates to Lunar (Chhankitek) format. Learn more about Khmer calendar.
You can install the package via composer:
composer require asorasoft/chhankitek
// In your Laravel controller, use this trait
use HasChhankitek;
// Convert a date to lunar format
$toLunarDate = $this->chhankiteck(Carbon\CarbonImmutable::now()->setTimezone('Asia/Phnom_Penh'));
$toLunarDate->toString(); // ថ្ងៃច័ន្ទ ៤ រោច ខែបឋមាសាឍ ឆ្នាំឆ្លូវ ត្រីស័ក ពុទ្ធសករាជ ២៥៦៥
// In your Laravel controller, use this trait
use HasChhankitek;
$toLunarDate = $this->chhankiteck(Carbon\CarbonImmutable::now()->setTimezone('Asia/Phnom_Penh'));
// 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')); // ថ្ងៃច័ន្ទ ៤ រោច ខែបឋមាសាឍ ឆ្នាំឆ្លូវ ត្រីស័ក ពុទ្ធសករាជ ២៥៦៥
The Chhankitek package implements caching to improve performance when converting dates to lunar format. When you convert a date using the package, the result is cached for one year (365 days) to minimize computational overhead for frequently accessed dates.
- Each converted date is cached
- Cache duration: 365 days (60 * 60 * 24 * 365 seconds)
- The package leverages Laravel's cache system, so it will use whatever cache driver you've configured for your application
composer test
Please see CHANGELOG for more information about recent changes.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email mabhelitc@gmail.com instead of using the issue tracker.
If you like this package and want to support me, you can buy me a coffee ☕
The MIT License (MIT). Please see License File for more information.
This library would not exist without the hard work of these people:
- Based on the algorithm by
Mr. Phylypo Tum
from Khmer Calendar - Ported from momentkh by
ThyrithSor
intoJava
- Khmer New Year Time Calculation
- Ported from MetheaX/khmer-chhankitek-calendar by
MetheaX
into aLaravel Package