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 * Which repetition this is
32 * Number of days until the event (positive) or since the event (negative)
40 public function __construct($title = null, $type = null, $date = null)
42 $this->title = $title;
48 * Checks if the event's date is within the given date.
49 * Also calculates the age and days since the event.
51 * @return boolean True if the event's date is within the given range
53 public function isWithin($strDate, $nDaysBefore, $nDaysAfter)
55 list($rYear, $rMonth, $rDay) = explode('-', $strDate);
56 list($eYear, $eMonth, $eDay) = explode('-', $this->date);
58 if ($rMonth == $eMonth && $rDay == $eDay) {
60 if ($eYear == '????') {
63 $this->age = $rYear - $eYear;
69 if ($eMonth < 3 && $rMonth > 10) {
71 } else if ($eMonth > 10 && $rMonth < 3) {
75 $rD = new \DateTime($strDate);
76 $eD = new \DateTime(($rYear + $yearOffset) . '-' . $eMonth . '-' . $eDay);
78 $nDiff = (int) $rD->diff($eD)->format('%r%a');
81 if ($eYear == '????') {
84 $this->age = $rYear - $eYear + $yearOffset;
88 return $nDiff <= $nDaysAfter;
90 return -$nDiff <= $nDaysBefore;
97 * @return integer x < 0: e1 is less than e2
98 * x > 0: e1 is larger than e2
100 public static function compare(Event $e1, Event $e2)
102 list($e1Year, $e1Month, $e1Day) = explode('-', $e1->date);
103 list($e2Year, $e2Month, $e2Day) = explode('-', $e2->date);
105 if ($e1Month < 3 && $e2Month > 10) {
107 } else if ($e1Month > 10 && $e2Month < 3) {
109 } else if ($e1Month != $e2Month) {
110 return $e1Month - $e2Month;
111 } else if ($e1Day != $e2Day) {
112 return $e1Day - $e2Day;
114 return strcmp($e1->title, $e2->title);