7 * Title of the event or name of the person that has the event
12 * Type of the event, e.g. "birthday"
18 * ???? as year is allowed
20 * @var string YYYY-MM-DD
25 * Reference date against which $age and $days are calculated
28 * @var string YYYY-MM-DD
33 * "Localized" $date used for calculations against $refDate.
34 * Month and day are the same as in $date, year is near $refDate's year.
36 * @var string YYYY-MM-DD
41 * Which repetition this is
48 * Number of days until the event (positive) or since the event (negative)
56 public function __construct($title = null, $type = null, $date = null)
58 $this->title = $title;
64 * Checks if the event's date is within the given date.
65 * Also calculates the age and days since the event.
67 * @return boolean True if the event's date is within the given range
69 public function isWithin($strDate, $nDaysPrev, $nDaysNext)
71 $this->refDate = $strDate;
72 list($rYear, $rMonth, $rDay) = explode('-', $strDate);
73 list($eYear, $eMonth, $eDay) = explode('-', $this->date);
75 if ($rMonth == $eMonth && $rDay == $eDay) {
76 $this->localDate = $strDate;
78 if ($eYear == '????') {
81 $this->age = $rYear - $eYear;
87 if ($eMonth < 3 && $rMonth > 10) {
89 } else if ($eMonth > 10 && $rMonth < 3) {
93 $this->localDate = ($rYear + $yearOffset) . '-' . $eMonth . '-' . $eDay;
94 $rD = new \DateTime($strDate);
95 $eD = new \DateTime($this->localDate);
97 $nDiff = (int) $rD->diff($eD)->format('%r%a');
100 if ($eYear == '????') {
103 $this->age = $rYear - $eYear + $yearOffset;
107 return $nDiff <= $nDaysNext;
109 return -$nDiff <= $nDaysPrev;
116 * @return integer x < 0: e1 is less than e2
117 * x > 0: e1 is larger than e2
119 public static function compare(Event $e1, Event $e2)
121 list($e1Year, $e1Month, $e1Day) = explode('-', $e1->date);
122 list($e2Year, $e2Month, $e2Day) = explode('-', $e2->date);
124 if ($e1Month < 3 && $e2Month > 10) {
126 } else if ($e1Month > 10 && $e2Month < 3) {
128 } else if ($e1Month != $e2Month) {
129 return $e1Month - $e2Month;
130 } else if ($e1Day != $e2Day) {
131 return $e1Day - $e2Day;
133 return strcmp($e1->title, $e2->title);