diff --git a/src/enko/RelativeDateParser/DateTranslator.php b/src/enko/RelativeDateParser/DateTranslator.php index 6cad103..ca41efd 100755 --- a/src/enko/RelativeDateParser/DateTranslator.php +++ b/src/enko/RelativeDateParser/DateTranslator.php @@ -45,7 +45,7 @@ class DateTranslator { } } - public function translate($string) { - return $this->translator->trans($string); + public function translate($string,$params = []) { + return $this->translator->trans($string,$params); } } \ No newline at end of file diff --git a/src/enko/RelativeDateParser/RelativeDateParser.php b/src/enko/RelativeDateParser/RelativeDateParser.php index d62146a..98aa6d9 100755 --- a/src/enko/RelativeDateParser/RelativeDateParser.php +++ b/src/enko/RelativeDateParser/RelativeDateParser.php @@ -34,6 +34,12 @@ class RelativeDateParser { return $this; } + $success = preg_match(RelativeDateType3::getRegex(),$string,$match); + if ($success === 1) { + $this->datetype = new RelativeDateType3($match); + return $this; + } + throw new \Exception('No DateType found.'); } diff --git a/src/enko/RelativeDateParser/RelativeDateType3.php b/src/enko/RelativeDateParser/RelativeDateType3.php new file mode 100755 index 0000000..6129ba0 --- /dev/null +++ b/src/enko/RelativeDateParser/RelativeDateType3.php @@ -0,0 +1,50 @@ +translate('/Jeder (\d+)\. Tag eines Monats/im'); + } + + private function getDay() { + return $this->day; + } + + public function getCurrent(\DateTime $now) { + if ($this->day > cal_days_in_month(CAL_GREGORIAN,$now->format('m'),$now->format('Y'))) { + throw new \BadMethodCallException(DateTranslator::getInstance()->translate('Angegebener Tag ist nicht im Monat %date% enthalten.',['date' => $now->format('F Y')])); + } + $date = new \DateTime(); + $date->setTimestamp (strtotime (sprintf ('%s %s %d', $this->getDay (), $now->format('F'), $now->format('Y')))); + $date->setTime($now->format('H'),$now->format('i')); + + return $date; + + } + + public function getNext(\DateTime $now) { + $date = clone $now; + $date->add(\DateInterval::createFromDateString('+1 Month')); + + return $this->getCurrent($date); + } + + function __construct($data) { + $day = intval($data[1]); + if (is_integer($day)) { + $this->day = $day; + } else { + throw new \BadMethodCallException(DateTranslator::getInstance()->translate('Tag wurde nicht angegeben oder ist falsch.')); + } + } +} \ No newline at end of file