Skip to content

Commit

Permalink
PHPDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
fisharebest committed May 7, 2017
1 parent 0784271 commit b4ca611
Show file tree
Hide file tree
Showing 9 changed files with 473 additions and 197 deletions.
56 changes: 56 additions & 0 deletions src/ArabicCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class ArabicCalendar implements CalendarInterface {
/**
* Determine the number of days in a specified month, allowing for leap years, etc.
*
* @param int $year
* @param int $month
*
* @return int
*/
public function daysInMonth($year, $month) {
if ($month === 2) {
return 28;
Expand All @@ -32,26 +40,60 @@ public function daysInMonth($year, $month) {
}
}

/**
* Determine the number of days in a week.
*
* @return int
*/
public function daysInWeek() {
return 7;
}

/**
* The escape sequence used to indicate this calendar in GEDCOM files.
*
* @return string
*/
public function gedcomCalendarEscape() {
return '@#DHIJRI@';
}

/**
* Determine whether or not a given year is a leap-year.
*
* @param int $year
*
* @return bool
*/
public function isLeapYear($year) {
return ((11 * $year + 14) % 30) < 11;
}

/**
* What is the highest Julian day number that can be converted into this calendar.
*
* @return int
*/
public function jdEnd() {
return PHP_INT_MAX;
}

/**
* What is the lowest Julian day number that can be converted into this calendar.
*
* @return int
*/
public function jdStart() {
return 1948440; // 1 Muharram 1 AH, 16 July 622 AD
}

/**
* Convert a Julian day number into a year/month/day.
*
* @param int $julian_day
*
* @return int[]
*/
public function jdToYmd($julian_day) {
$year = (int) ((30 * ($julian_day - 1948440) + 10646) / 10631);
$month = (int) ((11 * ($julian_day - $year * 354 - (int) ((3 + 11 * $year) / 30) - 1948086) + 330) / 325);
Expand All @@ -60,10 +102,24 @@ public function jdToYmd($julian_day) {
return array($year, $month, $day);
}

/**
* Determine the number of months in a year.
*
* @return int
*/
public function monthsInYear() {
return 12;
}

/**
* Convert a year/month/day to a Julian day number.
*
* @param int $year
* @param int $month
* @param int $day
*
* @return int
*/
public function ymdToJd($year, $month, $day) {
if ($month < 1 || $month > $this->monthsInYear()) {
throw new InvalidArgumentException('Month ' . $month . ' is invalid for this calendar');
Expand Down
30 changes: 15 additions & 15 deletions src/CalendarInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ interface CalendarInterface {
/**
* Determine the number of days in a specified month, allowing for leap years, etc.
*
* @param integer $year
* @param integer $month
* @param int $year
* @param int $month
*
* @return integer
* @return int
*/
public function daysInMonth($year, $month);

/**
* Determine the number of days in a week.
*
* @return integer
* @return int
*/
public function daysInWeek();

Expand All @@ -50,50 +50,50 @@ public function gedcomCalendarEscape();
/**
* Determine whether or not a given year is a leap-year.
*
* @param integer $year
* @param int $year
*
* @return boolean
* @return bool
*/
public function isLeapYear($year);

/**
* What is the highest Julian day number that can be converted into this calendar.
*
* @return integer
* @return int
*/
public function jdEnd();

/**
* What is the lowest Julian day number that can be converted into this calendar.
*
* @return integer
* @return int
*/
public function jdStart();

/**
* Convert a Julian day number into a year/month/day.
*
* @param integer $julian_day
* @param int $julian_day
*
* @return integer[]
* @return int[]
*/
public function jdToYmd($julian_day);

/**
* Determine the number of months in a year.
*
* @return integer
* @return int
*/
public function monthsInYear();

/**
* Convert a year/month/day to a Julian day number.
*
* @param integer $year
* @param integer $month
* @param integer $day
* @param int $year
* @param int $month
* @param int $day
*
* @return integer
* @return int
*/
public function ymdToJd($year, $month, $day);
}
54 changes: 54 additions & 0 deletions src/FrenchCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class FrenchCalendar implements CalendarInterface {
/**
* Determine the number of days in a specified month, allowing for leap years, etc.
*
* @param int $year
* @param int $month
*
* @return int
*/
public function daysInMonth($year, $month) {
if ($year <= 0) {
throw new InvalidArgumentException('Year ' . $year . ' is invalid for this calendar');
Expand All @@ -36,32 +44,64 @@ public function daysInMonth($year, $month) {
}
}

/**
* Determine the number of days in a week.
*
* @return int
*/
public function daysInWeek() {
return 10;
}

/**
* The escape sequence used to indicate this calendar in GEDCOM files.
*
* @return string
*/
public function gedcomCalendarEscape() {
return '@#DFRENCH R@';
}

/**
* Determine whether or not a given year is a leap-year.
*
* Leap years were based on astronomical observations. Only years 3, 7 and 11
* were ever observed. Moves to a gregorian-like (fixed) system were proposed
* but never implemented.
*
* @param int $year
*
* @return bool
*/
public function isLeapYear($year) {
return $year % 4 == 3;
}

/**
* What is the highest Julian day number that can be converted into this calendar.
*
* @return int
*/
public function jdEnd() {
return 2380687; // 31 DEC 1805 = 10 NIVO 0014
}

/**
* What is the lowest Julian day number that can be converted into this calendar.
*
* @return int
*/
public function jdStart() {
return 2375840; // 22 SEP 1792 = 01 VEND 0001
}

/**
* Convert a Julian day number into a year/month/day.
*
* @param int $julian_day
*
* @return int[]
*/
public function jdToYmd($julian_day) {
$year = (int) (($julian_day - 2375109) * 4 / 1461) - 1;
$month = (int) (($julian_day - 2375475 - $year * 365 - (int) ($year / 4)) / 30) + 1;
Expand All @@ -70,10 +110,24 @@ public function jdToYmd($julian_day) {
return array($year, $month, $day);
}

/**
* Determine the number of months in a year.
*
* @return int
*/
public function monthsInYear() {
return 13;
}

/**
* Convert a year/month/day to a Julian day number.
*
* @param int $year
* @param int $month
* @param int $day
*
* @return int
*/
public function ymdToJd($year, $month, $day) {
if ($month < 1 || $month > $this->monthsInYear()) {
throw new InvalidArgumentException('Month ' . $month . ' is invalid for this calendar');
Expand Down
47 changes: 21 additions & 26 deletions src/GregorianCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class GregorianCalendar extends JulianCalendar implements CalendarInterface {
public function daysInWeek() {
return 7;
}

/**
* The escape sequence used to indicate this calendar in GEDCOM files.
*
* @return string
*/
public function gedcomCalendarEscape() {
return '@#DGREGORIAN@';
}

public function jdEnd() {
return PHP_INT_MAX;
}

public function jdStart() {
return 1;
}

/**
* @param int $year
*
* @return bool
*/
public function isLeapYear($year) {
if ($year < 0) {
$year++;
Expand All @@ -49,9 +47,9 @@ public function isLeapYear($year) {
/**
* Convert a Julian day number into a year/month/day.
*
* @param integer $julian_day
* @param int $julian_day
*
* @return integer[]
* @return int[]
*/
public function jdToYmd($julian_day) {
$a = $julian_day + 32044;
Expand All @@ -64,33 +62,30 @@ public function jdToYmd($julian_day) {
$day = $e - (int) ((153 * $m + 2) / 5) + 1;
$month = $m + 3 - 12 * (int) ($m / 10);
$year = $b * 100 + $d - 4800 + (int) ($m / 10);
if ($year < 1) { // 0 is 1 BCE, -1 is 2 BCE, etc.
if ($year < 1) {
// 0 is 1 BCE, -1 is 2 BCE, etc.
$year--;
}

return array($year, $month, $day);
}

public function monthsInYear() {
return 12;
}

/**
* Convert a year/month/day into a Julian day number
*
* @param integer $year
* @param integer $month
* @param integer $day
* @param int $year
* @param int $month
* @param int $day
*
* @return integer
* @return int
*/
public function ymdToJd($year, $month, $day) {
if ($month < 1 || $month > $this->monthsInYear()) {
throw new InvalidArgumentException('Month ' . $month . ' is invalid for this calendar');
}

if ($year < 0) {
// 1 B.C.E. => 0, 2 B.C.E> => 1, etc.
// 1 BCE is 0, 2 BCE is -1, etc.
++$year;
}
$a = (int) ((14 - $month) / 12);
Expand All @@ -105,9 +100,9 @@ public function ymdToJd($year, $month, $day) {
*
* Uses the algorithm found in PHP’s ext/calendar/easter.c
*
* @param integer $year
* @param int $year
*
* @return integer
* @return int
*/
public function easterDays($year) {
// The “golden” number
Expand Down

0 comments on commit b4ca611

Please sign in to comment.