X-Git-Url: https://git.cweiske.de/bdrem.git/blobdiff_plain/441c72bbf3d29be5c7f5eb0fd43ac267fe059c2f..e86787a8eb6a31fbe95f1a3854d66e25e5e63c67:/src/bdrem/Event.php?ds=sidebyside diff --git a/src/bdrem/Event.php b/src/bdrem/Event.php index 65e4b9b..43b9c92 100644 --- a/src/bdrem/Event.php +++ b/src/bdrem/Event.php @@ -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');