European Civil Calendar#
Civil calendar covers a very common European use case when the calendar changes from Julian to Gregorian. Civil calendar accepts a switch date, a first day that uses Gregorian calendar, as a parameter.
Predefined Switch Dates#
This list mostly includes non-ambiguous dates, excluding for example Germany that has more than 20 switch dates depending on exact region.
Constant |
Switch Date |
Comments |
---|---|---|
|
|
Minimum possible. The calendar doesn’t handle negative difference between Julian and Gregorian |
|
|
Invention of Gregorian. Switch date for Italy, Spain, Portugal, Poland and many other Catholic regions |
|
|
|
|
|
|
|
|
|
|
|
Ignores the period of 1700-1712 when Sweden was 1 day out of sync with Julian |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Factories#
You can create an instance of date from either date components or a Y-m-d
string format (years can be negative):
<?php
use Arokettu\Date\CivilCalendar;
use Arokettu\Date\Month;
// 1615-04-15 Gregorian or 1615-04-05 Julian
$date = CivilCalendar::for(CivilCalendar::ITALY)->create(1615, Month::April, 15);
// 1615-04-25 Gregorian or 1615-04-15 Julian
$date = CivilCalendar::for(CivilCalendar::BRITAIN)->create(1615, Month::April, 15);
// DomainException: Switch day cannot be earlier than "200-03-01", "200-01-01" (Julian day 1794109) given
$date = CivilCalendar::for(Calendar::parse('200-01-01'))->create(1615, Month::April, 15);
// DomainException: "1582-10-10" likely belongs to the switch gap. Dates between "1582-10-04" and "1582-10-15" are invalid
$date = CivilCalendar::for(CivilCalendar::ITALY)->create(1582, Month::October, 10);
Getters and Helpers#
There are getters for day, month, year, string representation and array representation, also calendar has helpers to reuse the switch date:
<?php
use Arokettu\Date\CivilCalendar;
use Arokettu\Date\Date;
$italy = CivilCalendar::for(CivilCalendar::ITALY);
// use switch date as an example
$date = Date::createFromJulianDay(CivilCalendar::ITALY); // Gregorian
$date->civil(CivilCalendar::ITALY)->getDay(); // 15
// or
$italy->civilDate($date)->getDay(); // 15
$date->civil(CivilCalendar::ITALY)->getMonth(); // Month::October
// or
$italy->civilDate($date)->getMonth(); // Month::October
$date->civil(CivilCalendar::ITALY)->getMonthNumber(); // 10
// or
$italy->civilDate($date)->getMonthNumber(); // 10
$date->civil(CivilCalendar::ITALY)->getYear(); // 1582
// or
$italy->civilDate($date)->getYear(); // 1582
$date->civil(CivilCalendar::ITALY)->getDateArray(); // [$y, $m, $d]: [1582, 10, 15]
// or
$italy->civilDate($date)->getDateArray(); // [$y, $m, $d]: [1582, 10, 15]
$date->civil(CivilCalendar::ITALY)->toString(); // Y-m-d: 1582-10-15
// or
$italy->dateToString($date); // Y-m-d: 1582-10-15
// going over the switch date will get us Julian
echo $date->subDays(1)->civil(CivilCalendar::ITALY)->toString(); // 1582-10-04