Download the PHP package andegna/calender without Composer
On this page you can find all versions of the php package andegna/calender. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andegna/calender
More information about andegna/calender
Files in andegna/calender
Package calender
Short Description 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.
License MIT
Informations about the package calender
Andegna Calender 
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.
- Basic Usage
- Requirement
- Installation
- Conversion
- From Ethiopian Date
- From Timestamp
- From DateTime object
- From date string
- From the system time
- To DateTime
- Low level Conversion
- How PHP calendar conversion works
- From JDN
- To JDN
- Practical Example
- Manipulation
- Warning
- Manipulating the internal date time
- Formatting
- Introduction
- Additional character formats
- Constants
- Holidays
- Easter
- Validators
- Contributing
Basic Usage :hammer: ↑
Just to give you the 10,000-foot view (:airplane:) of the package.
Format it
Modify it
Get what you want :wink:
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.
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.
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.
From Ethiopian Date ↑
You can create an Andegna\DateTime
from a given Ethiopia Date.
Let's "create"
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
And you are done. You can also or pass a DateTimeZone
object if you want too
From DateTime object ↑
If you already have a DateTime
object, just give it to me :smile:
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
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
From the system time ↑
You obviously can do this
To DateTime ↑
If you want the internal DateTime
object (A.K.A convert to gregorian calendar).
Warning: the returned DateTime object is just a clone. So changes/modification to the returned object will not affect the Ethiopic date.
Low level Conversion ↑
If you are a geek like me, you are probably interested in Calendar coz it has Astronomy, Maths, and History.
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 convert between calendar systems, you must first convert to Julian Day Count, then to the calendar system of your choice. Julian Day Count is very different from the Julian Calendar! For more information on Julian Day Count, visit » http://www.hermetic.ch/cal_stud/jdn.htm. For more information on calendar systems visit » http://www.fourmilab.ch/documents/calendar/. Excerpts from this page are included in these instructions and are in quotes.
Those words are straight from the php docs.
So we need to implement two things to convert Ethiopian date to any other calendar.
- Convert Ethiopian Date To Julian Date Count
- Convert Julian Date Count To Ethiopian Date
If you wanna know the algorithms check out the only reliable resource at this link.
or check out my gist on GitHub at this link
From JDN ↑
To JDN ↑
Practical Example ↑
Now with those handy tools in our hand, we can convert Ethiopian date to any other date.
Let's convert to Jewish for example
Let's convert Julian Calendar to Ethiopian Calendar as a second example
List of supported calendars built into PHP
- French Republican Calendar
- Gregorian Calendar
- Jewish calendar
- Julian Calendar
- Unix (I know what you are thinking. It's not a calendar but it handy)
Click here to read more about those calendar function
Manipulation ↑
Warning ↑
The DateTime processor works on the internal gregorian
DateTime
. And manipulating months and years probably give an expected results.
Manipulating the internal date time ↑
You probably need to read about DateTimeInterval if you don't already know.
To give you a short summary, DateInterval
implements the ISO 8601 durations.
Durations are a component of time intervals and define the amount of intervening time in a time interval.
Durations are represented by the format P[n]Y[n]M[n]DT[n]H[n]M[n]S
or P[n]W
.
In these representations, the [n] is replaced by the value for each of the date and time elements that follow the [n].
Leading zeros are not required. The capital letters P, Y, M, W, D, T, H, M, and S are designators for each of the date and time elements and are not replaced.
- P is the duration designator (for the period) placed at the start of the duration representation.
- Y is the year designator that follows the value for the number of years.
- M is the month designator that follows the value for the number of months.
- W is the week designator that follows the value for the number of weeks.
- D is the day designator that follows the value for the number of days.
- T is the time designator that precedes the time components of the representation.
- H is the hour designator that follows the value for the number of hours.
- M is the minute designator that follows the value for the number of minutes.
- S is the second designator that follows the value for the number of seconds.
For example, "P3Y6M4DT12H30M5S" represents a duration of "three years, six months, four days, twelve hours, thirty minutes, and five seconds".
If you want to get the difference between dates
will output something like this
Formatting ↑
Introduction ↑
PHP built-in DateTime
class has a format
method used to format dates.
Read about the format method here
Read out the format characters here
If you read or already know how PHP date function works, you already know how exactly the formatting works.
Additional character formats ↑
Format Character | Description | Example |
---|---|---|
x | Orthodox day name | 1 => ልደታ, 12 => ሚካኤል |
X | Orthodox year name | ማቴዎስ, ማርቆስ, ሉቃስ or ዮሐንስ |
E | Era in Amharic | ዓ/ዓ or ዓ/ም |
K | Year in geez numeber | ፳፻፱ |
V | Day in geez numebr | ፪ |
Constants ↑
We have already defined some handy constants to print as it's custom in Ethiopia :heart: .
As you saw 3D, the constants all start with DATE_
and followed by ETHIOPIAN
or GEEZ
.
The one followed by GEEZ
will return the day and the year in geez and the ETHIOPIAN
with spit an ASCII numbers which we Ethiopian always use.
Lastly, if you append _ORTHODOX
you will get the orthodox day name and orthodox year name.
Holidays ↑
Easter ↑
Calculating easter date feels like shooting a moving target. And everyone thinks calculating easter date is like impossible, some think like it's only possible if you are a deeply religious and some think it's decided by the church. But calculating easter date ( also called Computus) is not that much complex.
In the simplest form, Easter is the first Sunday following the full moon that follows the northern spring (vernal) equinox.
That sounds complex and was hard for the ages but not for the 21st century.
If you are interested in HOW it's calculated, I will post it on my upcoming blog. You can read this in the meanwhile.
Let's see how you can get the easter date for a given year
will output
Validators ↑
Validation. You probably need that too.
To check if Ethiopia date (given day
, month
and year
) is valid you need to do all this
- Check if the
day
is between1
and30
inclusive - Check if the
month
is between1
and13
inclusive - If the
month
is13
check if theday
is between1
and6
inclusive - If the
month
is13
and theday
is6
check if the year is a leap year
or you can use our validator
DateValidator
LeapYearValidator
Contributing ↑
Fork it
Create your feature branch (git checkout -b my-new-feature)
Commit your changes (git commit -am 'Add some feature')
Push to the branch (git push origin my-new-feature)
Create new Pull Request