PHP code example of melakudemeke / kenat-php

1. Go to this page and download the library: Download melakudemeke/kenat-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

melakudemeke / kenat-php example snippets


use Kenat\Kenat;

$today = new Kenat();
echo $today->format(); // e.g. "ጥቅምት 5 2018"

$date = new Kenat('2016/10/5');
echo $date->formatInGeezAmharic(); // "ሰኔ ፭ ፳፻፲፮"
echo $date->getGregorian()->year;  // 2024

$nextWeek = $date->addDays(7);
echo $nextWeek->formatShort(); // "2016/10/12"

use Kenat\Conversions;

$gregorian = Conversions::toGC(2016, 1, 1); // GregorianDate{ year: 2023, month: 9, day: 12 }
$ethiopian = Conversions::toEC(2024, 6, 7); // EthiopianDate{ year: 2016, month: 10, day: 7 }

use Kenat\BahireHasab;
use Kenat\Holidays;
use Kenat\HolidayTags;

$bahireHasab = BahireHasab::calculate(2016);
echo $bahireHasab['evangelist']['name']; // "ዮሐንስ"
echo $bahireHasab['movableFeasts']['fasika']->ethiopian->day; // 27 (Fasika/Easter)

$publicHolidays = Holidays::getHolidaysForYear(2016, ['filter' => HolidayTags::PUBLIC]);
foreach ($publicHolidays as $holiday) {
    echo "{$holiday->name}: {$holiday->ethiopian->month}/{$holiday->ethiopian->day}\n";
}

use Kenat\Kenat;

$k = new Kenat('2015/6/10');
$result = $k->addDays(5)->addMonths(-1)->addYears(2);
// { year: 2017, month: 5, day: 15 }

$a = new Kenat('2016/06/10');
$b = new Kenat('2016/06/05');
$a->diffInDays($b); // 5
$a->isAfter($b);    // true

use Kenat\MonthGrid;

$grid = MonthGrid::create([
    'year' => 2016,
    'month' => 1,
    'mode' => 'christian', // 'public' | 'christian' | 'muslim' | null
    'weekdayLang' => 'amharic',
]);

echo $grid['monthName']; // "መስከረም"
foreach ($grid['days'] as $day) {
    if ($day === null) continue; // leading padding cell
    // $day['holidays'] 

use Kenat\Time;

$time = Time::fromGregorian(17, 30);
echo $time->format(); // "፲፩:፴ ጠዋት"

$time->toGregorian(); // ['hour' => 17, 'minute' => 30]

use Kenat\Fasting;
use Kenat\FastingKeys;

$period = Fasting::getFastingPeriod(FastingKeys::ABIY_TSOME, 2016);
echo "{$period->start->month}/{$period->start->day} - {$period->end->month}/{$period->end->day}";
bash
composer