Skip to main content
πŸ•ŠοΈ αž€αž˜αŸ’αž–αž»αž‡αžΆαžαŸ’αžšαžΌαžœαž€αžΆαžšαžŸαž“αŸ’αžαž·αž—αžΆαž–
CAMBODIA NEEDS PEACE πŸ‡°πŸ‡­

αž™αžΎαž„αž‚αžΆαŸ†αž‘αŸ’αžšαžŠαž›αŸ‹αž‘αžΆαž αžΆαž“αžαŸ’αž˜αŸ‚αžšαž‘αžΆαŸ†αž„αž’αžŸαŸ‹αžŠαŸ‚αž›αž€αžΆαžšαž–αžΆαžšαž‘αžΉαž€αžŠαžΈαž‡αžΆαžαž· β€’ We stand with our brave soldiers defending our homeland

Complete Documentation

Chhankitek Documentation

Everything you need to integrate Khmer Lunar calendar conversions into your Laravel application

Documentation

Installation

You can install the package via Composer:

composer require asorasoft/chhankitek

The package will automatically register its service provider. No additional configuration is needed.

Basic Usage

Using the Trait

In your Laravel controller, use the HasChhankitek trait:

use Asorasoft\Chhankitek\Traits\HasChhankitek;
use Carbon\CarbonImmutable;

class YourController extends Controller
{
    use HasChhankitek;

    public function index()
    {
        $lunarDate = $this->chhankiteck(
            CarbonImmutable::now()->setTimezone('Asia/Phnom_Penh')
        );

        echo $lunarDate->toString();
        // Output: αžαŸ’αž„αŸƒαž…αŸαž“αŸ’αž‘ ៀ αžšαŸ„αž… αžαŸ‚αž”αž‹αž˜αžΆαžŸαžΆαž αž†αŸ’αž“αžΆαŸ†αž†αŸ’αž›αžΌαžœ αžαŸ’αžšαžΈαžŸαŸαž€ αž–αž»αž‘αŸ’αž’αžŸαž€αžšαžΆαž‡ ្αŸ₯៦αŸ₯
    }
}

Using the Helper Function

Alternatively, you can use the global toLunarDate helper:

use Carbon\CarbonImmutable;

$lunarDate = toLunarDate(
    CarbonImmutable::now()->setTimezone('Asia/Phnom_Penh')
);

echo $lunarDate->toString();

Important: Always use CarbonImmutable (not Carbon) and set the timezone to 'Asia/Phnom_Penh'.

Available Methods

The KhmerLunarDate object provides the following methods:

getDayOfWeek()

Returns the Khmer day of the week.

$lunarDate->getDayOfWeek(); // αž’αžΆαž‘αž·αžαŸ’αž™, αž…αŸαž“αŸ’αž‘, αž’αž„αŸ’αž‚αžΆαžš, αž–αž»αž’, αž–αŸ’αžšαž αžŸαŸ’αž”αžαž·αŸ, αžŸαž»αž€αŸ’αžš, αžŸαŸ…αžšαŸ

getLunarDay()

Returns the lunar day with moon status (αž€αžΎαž for waxing, αžšαŸ„αž… for waning).

$lunarDate->getLunarDay(); // αŸ‘αž€αžΎαž, αŸ’αž€αžΎαž, αŸ‘αŸ€αžšαŸ„αž…, etc.

getLunarMonth()

Returns the Khmer lunar month name.

$lunarDate->getLunarMonth(); // αž…αŸαžαŸ’αžš, αž–αž·αžŸαžΆαž, αž‡αŸαžŸαŸ’αž‹, ធអសអឍ, etc.

getLunarZodiac()

Returns the animal year (Khmer zodiac).

$lunarDate->getLunarZodiac(); // αž‡αžΌαž, αž†αŸ’αž›αžΌαžœ, αžαžΆαž›, αžαŸ„αŸ‡, αžšαŸ„αž„, αž˜αŸ’αžŸαžΆαž‰αŸ‹, មមី, αž˜αž˜αŸ‚, αžœαž€, αžšαž€αžΆ, αž…, αž€αž»αžš

getLunarEra()

Returns the era year (10-year cycle).

$lunarDate->getLunarEra(); // αžαŸ’αžšαžΈαžŸαŸαž€, αž…αžαŸ’αžœαžΆαžŸαŸαž€, αž”αž‰αŸ’αž…αžŸαŸαž€, etc.

getLunarYear()

Returns the Buddhist Era year in Khmer numerals.

$lunarDate->getLunarYear(); // ្αŸ₯៦αŸ₯, ្αŸ₯៦៦, etc.

toString()

Returns the complete lunar date as a formatted string.

$lunarDate->toString();
// αžαŸ’αž„αŸƒαž…αŸαž“αŸ’αž‘ ៀ αžšαŸ„αž… αžαŸ‚αž”αž‹αž˜αžΆαžŸαžΆαž αž†αŸ’αž“αžΆαŸ†αž†αŸ’αž›αžΌαžœ αžαŸ’αžšαžΈαžŸαŸαž€ αž–αž»αž‘αŸ’αž’αžŸαž€αžšαžΆαž‡ ្αŸ₯៦αŸ₯

Caching

The Chhankitek package implements automatic caching to improve performance:

  • Each converted date is cached automatically
  • Cache duration: 365 days
  • Uses Laravel's default cache driver (configured in your application)
  • No manual cache management required

The package leverages Laravel's cache system, so conversions are cached efficiently whether you're using Redis, Memcached, or the file cache driver.

Requirements

  • PHP: ^8.2
  • Laravel: ^10.0 | ^11.0 | ^12.0
  • Carbon: CarbonImmutable (included with Laravel)

Examples

Example 1: Convert Current Date

$today = toLunarDate(
    CarbonImmutable::now()->setTimezone('Asia/Phnom_Penh')
);

echo "Day: " . $today->getDayOfWeek();
echo "Lunar Day: " . $today->getLunarDay();
echo "Month: " . $today->getLunarMonth();
echo "Year: " . $today->getLunarYear();

Example 2: Convert Specific Date

$date = CarbonImmutable::createFromFormat(
    'Y-m-d',
    '2024-04-14'
)->setTimezone('Asia/Phnom_Penh');

$lunarDate = toLunarDate($date);
echo $lunarDate->toString();

Example 3: Display in Blade Template

// In Controller
public function index()
{
    $lunarDate = toLunarDate(
        CarbonImmutable::now()->setTimezone('Asia/Phnom_Penh')
    );

    return view('welcome', compact('lunarDate'));
}

// In Blade (welcome.blade.php)
<div>
    <h1>{{ $lunarDate->toString() }}</h1>
    <p>Animal Year: {{ $lunarDate->getLunarZodiac() }}</p>
</div>

Example 4: Using in API

Route::get('/api/lunar-date', function (Request $request) {
    $date = $request->input('date')
        ? CarbonImmutable::parse($request->input('date'))
        : CarbonImmutable::now();

    $date = $date->setTimezone('Asia/Phnom_Penh');
    $lunarDate = toLunarDate($date);

    return response()->json([
        'gregorian' => $date->format('Y-m-d'),
        'lunar' => [
            'full' => $lunarDate->toString(),
            'day_of_week' => $lunarDate->getDayOfWeek(),
            'lunar_day' => $lunarDate->getLunarDay(),
            'month' => $lunarDate->getLunarMonth(),
            'zodiac' => $lunarDate->getLunarZodiac(),
            'era' => $lunarDate->getLunarEra(),
            'year' => $lunarDate->getLunarYear(),
        ],
    ]);
});

Understanding the Khmer Calendar

Lunar Months

The Khmer lunar calendar has 12 standard months. In leap years, an additional month (αž”αž‹αž˜αžΆαžŸαžΆαž) is added:

  • αž˜αž·αž‚αžŸαž·αžš (Mikasar)
  • αž”αž»αžŸαŸ’αžŸ (Boss)
  • αž˜αžΆαžƒ (Meak)
  • αž•αž›αŸ’αž‚αž»αž“ (Phalguna)
  • αž…αŸαžαŸ’αžš (Chaet)
  • αž–αž·αžŸαžΆαž (Pisak)
  • αž‡αŸαžŸαŸ’αž‹ (Chet)
  • ធអសអឍ (Asath)
  • αžŸαŸ’αžšαžΆαž–αžŽαŸ (Srapon)
  • αž—αž‘αŸ’αžšαž”αž‘ (Phutrobot)
  • αž’αžŸαŸ’αžŸαž»αž‡ (Assoch)
  • αž€αžαŸ’αžαž·αž€ (Kadek)

Lunar Days

Each lunar month is divided into two phases:

  • αž€αžΎαž (Kaet): Waxing moon (days 1-15)
  • αžšαŸ„αž… (Roch): Waning moon (days 1-15)

Zodiac Animals (12-year cycle)

αž‡αžΌαž - Rat
αž†αŸ’αž›αžΌαžœ - Ox
αžαžΆαž› - Tiger
αžαŸ„αŸ‡ - Rabbit
αžšαŸ„αž„ - Dragon
αž˜αŸ’αžŸαžΆαž‰αŸ‹ - Snake
មមី - Horse
αž˜αž˜αŸ‚ - Goat
αžœαž€ - Monkey
αžšαž€αžΆ - Rooster
αž… - Dog
αž€αž»αžš - Pig

Leap Years

The Khmer calendar has two types of leap years:

  • Leap Month Year (Adhikameas): An extra 13th month (αž”αž‹αž˜αžΆαžŸαžΆαž) is added, making the year 384 days long
  • Leap Day Year: An extra day is added to the month of αž‡αŸαžŸαŸ’αž‹, making the year 355 days long
  • Regular Year: 354 days with 12 months

Learn More: Visit Khmer Calendar for detailed information about the Khmer calendar system.

API Reference

HasChhankitek Trait

chhankiteck(CarbonImmutable $target): KhmerLunarDate

Converts a Gregorian date to Khmer lunar date format.

Helper Function

toLunarDate(CarbonImmutable $target): KhmerLunarDate

Global helper function for date conversion.

KhmerLunarDate Methods

Method Return Type Description
getDayOfWeek() string Khmer day of week
getLunarDay() string Lunar day with moon status
getLunarMonth() string Khmer lunar month name
getLunarZodiac() string Animal year (zodiac)
getLunarEra() string Era year (10-year cycle)
getLunarYear() string Buddhist Era year (Khmer numerals)
toString() string Complete formatted date string

Contributing

Contributions are welcome! Please see the CONTRIBUTING.md file for details.

Found a security issue? Please email mabhelitc@gmail.com instead of using the issue tracker.