html renderer, console renderer uses pear's Console_Table
[bdrem.git] / src / bdrem / Event.php
index 65e4b9b498b54a5d53634d14456b8adf10938c08..43b9c92ecbf0f13ca8c53546445b96e3cfadc13d 100644 (file)
@@ -21,6 +21,22 @@ class Event
      */
     public $date;
 
+    /**
+     * Reference date against which $age and $days are calculated
+     * (often today)
+     *
+     * @var string YYYY-MM-DD
+     */
+    public $refDate;
+
+    /**
+     * "Localized" $date used for calculations against $refDate.
+     * Month and day are the same as in $date, year is near $refDate's year.
+     *
+     * @var string YYYY-MM-DD
+     */
+    public $localDate;
+
     /**
      * Which repetition this is
      *
@@ -52,10 +68,12 @@ class Event
      */
     public function isWithin($strDate, $nDaysBefore, $nDaysAfter)
     {
+        $this->refDate = $strDate;
         list($rYear, $rMonth, $rDay) = explode('-', $strDate);
         list($eYear, $eMonth, $eDay) = explode('-', $this->date);
 
         if ($rMonth == $eMonth && $rDay == $eDay) {
+            $this->localDate = $strDate;
             $this->days = 0;
             if ($eYear == '????') {
                 $this->age = null;
@@ -72,8 +90,9 @@ class Event
             $yearOffset = -1;
         }
 
+        $this->localDate = ($rYear + $yearOffset) . '-' . $eMonth . '-' . $eDay;
         $rD = new \DateTime($strDate);
-        $eD = new \DateTime(($rYear + $yearOffset) . '-' . $eMonth . '-' . $eDay);
+        $eD = new \DateTime($this->localDate);
 
         $nDiff = (int) $rD->diff($eD)->format('%r%a');