SkillAgentSearch skills...

Calender

If you ever want to convert Ethiopian Calender to any other calender system (like the Gregorian Calender) this is the right package for you. And by the way it also support Amharic date formatting and much much more.

Install / Use

/learn @andegna/Calender
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Andegna Calender From Ethiopia

Build Status StyleCI Scrutinizer Code Quality Code Coverage Total Downloads Latest Stable Version Latest Unstable Version License FOSSA Status

SymfonyInsight

If you ever want to convert Ethiopian Calender to any other calendar system (like the Gregorian Calendar) this is the right (well-tested, well designed, high quality) package for you.

And by the way it also supports Amharic date formatting and much much more.

<a name="top"></a>

<a name="basic-usage-hammer"></a>

Basic Usage :hammer:

Just to give you the 10,000-foot view (:airplane:) of the package.

// create a gregorian date using PHP's built-in DateTime class
$gregorian = new DateTime('next monday');

// just pass it to Andegna\DateTime constractor and you will get $ethiopian date
$ethipic = new Andegna\DateTime($gregorian);

Format it

// format it
// ሰኞ፣ ግንቦት ፯ ቀን (ሥላሴ) 00:00:00 እኩለ፡ሌሊት EAT ፳፻፱ (ማርቆስ) ዓ/ም
echo $ethipic->format(Andegna\Constants::DATE_GEEZ_ORTHODOX);

// ሰኞ፣ ግንቦት 07 ቀን 00:00:00 እኩለ፡ሌሊት EAT 2009 ዓ/ም
echo $ethipic->format(Andegna\Constants::DATE_ETHIOPIAN);

Modify it

$ethipic->modify('+8 hours');
$ethipic->sub(new DateInterval('PT30M')); // 30 minutes

// ሰኞ, 07-ግን-2009 07:30:00 EAT
echo $ethipic->format(DATE_COOKIE);

Get what you want :wink:

echo $ethipic->getYear();   // 2009
echo $ethipic->getMonth();  // 9
echo $ethipic->getDay();    // 7

echo $ethipic->getTimestamp(); // 1494822600

// turn it back to gregorian 
// Monday, 15-May-2017 07:30:00 EAT
echo $ethipic->toGregorian()->format(DATE_COOKIE);

<a name="requirement"></a>

Requirement

Andegna Calender requires php: >=7.0 with fire and blood :fire: :dragon:.

Please notice the name of this package is andegna/calender not andegna/calendar. It's a spelling mistake am not intending to fix.

<a name="installation"></a>

Installation

Andegna Calender utilizes Composer to manage its dependencies. So, before using this, make sure you have Composer installed on your machine.

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

If you never used composer before :flushed:, PLEASE read some intro here before you write any PHP code again.

composer require andegna/calender

<a name="conversion"></a>

Conversion

Before we talk about calendar conversion, we better know how the Andegna\DateTime class works internally.

The Andegna\DateTime class is just a wrapper around PHP's built-in DateTime object and implements the PHP DateTimeInterface (OK! I lied on one part but trust me you don't wanna know that :smile:).

So Andegna\DateTime keep hold of the gregorian date and overrides the format, getTimestamp, add, 'diff' and such methods to give you an Ethiopian Calendar equivalent.

That's how it basically works.

<a name="from-Ethiopian-Date"></a>

From Ethiopian Date

You can create an Andegna\DateTime from a given Ethiopia Date.

Let's "create"

$millennium = Andegna\DateTimeFactory::of(2000, 1, 1);

// ረቡዕ፣ መስከረም 01 ቀን (ልደታ) 00:00:00 እኩለ፡ሌሊት EAT 2000 (ማቴዎስ) ዓ/ም
echo $millennium->format(\Andegna\Constants::DATE_ETHIOPIAN_ORTHODOX).PHP_EOL;

// Wednesday, 12-Sep-2007 00:00:00 EAT
echo $millennium->toGregorian()->format(DATE_COOKIE).PHP_EOL;

$fall_of_derg = Andegna\DateTimeFactory::of(1983, 9, 20, 7, 43, 21, new DateTimeZone('Africa/Addis_Ababa'));

// ማክሰኞ፣ ግንቦት 20 ቀን (ሕንፅተ) 07:43:21 ጡዋት EAT 1983 (ዮሐንስ) ዓ/ም
echo $fall_of_derg->format(\Andegna\Constants::DATE_ETHIOPIAN_ORTHODOX).PHP_EOL;

// Tuesday, 28-May-1991 07:43:21 EAT
echo $fall_of_derg->toGregorian()->format(DATE_COOKIE).PHP_EOL;

<a name="from-timestamp"></a>

From Timestamp

Let's assume you have a timestamp from same were probably time() function or from some kind of database.

You can get Andegna\DateTime object like this

$timestamp = time(); // or some other place ¯\_(ツ)_/¯

$ethipic = Andegna\DateTimeFactory::fromTimestamp($timestamp);

And you are done. You can also or pass a DateTimeZone object if you want too

$sheger = new DateTimeZone('Africa/Addis_Ababa');

$ethiopic = Andegna\DateTimeFactory::fromTimestamp($timestamp, $sheger);

<a name="from-dateTime-object"></a>

From DateTime object

If you already have a DateTime object, just give it to me :smile:

$gregorian = new DateTime('Thu, 11 May 2017 19:01:26 GMT');
$ethiopic = Andegna\DateTimeFactory::fromDateTime($gregorian);

// or just pass it through the constractor
$ethiopic = new Andegna\DateTime(new DateTime('next sunday'));

<a name="from-date-string"></a>

From date string

This is not actually part of this package but someone probably having a hard time.

It generally boils down to two options. Do you know the format of the date string or not.

If you know the format of the date (you probably should) you can create a gregorian DateTime like this

// passing the format followed by the date string you got
$gregorian1 = DateTime::createFromFormat('j-M-Y', '15-Feb-2009');
$gregorian2 = DateTime::createFromFormat('m-j-Y', '12-31-1999');
$gregorian3 = DateTime::createFromFormat('Y-m-d H:i:s', '2009-02-15 15:16:17');

To figure out the format please check this link or search for "PHP date function".

But if don't know the format is or don't care to figure it out just try to pass it to the DateTime constructor. It will "probably" figure out the format of the date string

$gregorian1 = new DateTime('next sunday');
$gregorian2 = new DateTime('yesterday');
$gregorian3 = new DateTime('1999-12-31');
$gregorian4 = new DateTime('2123-12-31 12:34:56');

$gregorian_bad = new DateTime('12-31-1999'); // this one probably fails

<a name="from-the-system-time"></a>

From the system time

You obviously can do this

$gregorian = new DateTime('now');
$ethiopic = Andegna\DateTimeFactory::fromDateTime($gregorian);

// but we provided some shortcuts
$now1 = \Andegna\DateTimeFactory::now();
$now2 = new DateTime();

// if you wanna specify time zone
$sheger = new DateTimeZone('Africa/Addis_Ababa');
$now3 = \Andegna\DateTimeFactory::now($sheger);

<a name="to-datetime"></a>

To DateTime

If you want the internal DateTime object (A.K.A convert to gregorian calendar).

// create some Ethiopian date how ever you want
$ethiopian_date = \Andegna\DateTimeFactory::now();

// you get a PHP DateTime object to play with
$gregorian = $now->toGregorian();

Warning: the returned DateTime object is just a clone. So changes/modification to the returned object will not affect the Ethiopic date.

<a name="low-level-conversion"></a>

Low level Conversion

If you are a geek like me, you are probably interested in Calendar coz it has Astronomy, Maths, and History.

<a name="how-php-calendar-conversion-works"></a>

How PHP calendar conversion works

The calendar extension presents a series of functions to simplify converting between different calendar formats (except Ethiopian). The intermediary or standard it is based on is the Julian Day Count. The Julian Day Count is a count of days starting from January 1st, 4713 B.C. To conve

View on GitHub
GitHub Stars70
CategoryCustomer
Updated7d ago
Forks24

Languages

PHP

Security Score

100/100

Audited on Mar 24, 2026

No findings