Skip to content

Commit 5bdb791

Browse files
committed
Add current BE year calculation example and update KhmerCalculator logic for accurate year determination
1 parent 58f51de commit 5bdb791

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

examples/current_be_year.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
require_once __DIR__ . '/../vendor/autoload.php';
3+
4+
use PPhatDev\LunarDate\KhmerDate;
5+
6+
// ANSI color codes
7+
$colors = [
8+
'yellow' => "\033[33m",
9+
'green' => "\033[32m",
10+
'cyan' => "\033[36m",
11+
'magenta'=> "\033[35m",
12+
'reset' => "\033[0m"
13+
];
14+
15+
echo "{$colors['yellow']}=== Running Current BE Year Calculation ==={$colors['reset']}\n";
16+
$khmerDate = new KhmerDate();
17+
18+
echo "{$colors['green']}Current BE Year: {$khmerDate->khYear()}{$colors['reset']} \n";
19+
echo "{$colors['cyan']}Current Gregorian Year: {$khmerDate->format('Y')}{$colors['reset']} \n";
20+
echo "{$colors['magenta']}Current Khmer Month: {$khmerDate->khMonth()}{$colors['reset']} \n";
21+
echo "{$colors['yellow']}Current Khmer Day: {$khmerDate->khDay()}{$colors['reset']} \n";
22+
echo "{$colors['green']}Current Khmer Date: {$khmerDate->format('d-m-Y')}{$colors['reset']} \n";

src/KhmerCalculator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public static function getNumberOfDayInGregorianYear(int $adYear): int
315315
public static function getBEYear(DateTime $dateTime): int
316316
{
317317
$visakhaBochea = self::getVisakhaBochea((int)$dateTime->format('Y'));
318-
if ($dateTime >= $visakhaBochea) {
318+
if ($dateTime > $visakhaBochea) {
319319
return (int)$dateTime->format('Y') + 544;
320320
} else {
321321
return (int)$dateTime->format('Y') + 543;

0 commit comments

Comments
 (0)