This repository has been archived on 2024-01-26. You can view files and clone it, but cannot push or open issues or pull requests.
RelativeDateParser/src/enko/RelativeDateParser/RelativeDateType2.php
Tim Schumacher f31f5691fa Add missing commits. *Again*
*grml* this is realy annoying.
2016-06-02 14:52:40 +02:00

47 lines
1.4 KiB
PHP
Executable file

<?php
namespace enko\RelativeDateParser;
class RelativeDateType2 {
private $interval = -1;
private $days_or_week = -1;
public static function getRegex() {
return DateTranslator::getInstance()->translate('/^Alle (\d+) ([Wochen|Tage]+)$/im');
}
public function getCurrent(\DateTime $now) {
return $now;
}
public function getNext(\DateTime $now) {
$date = clone $now;
if ($this->days_or_week == 0) {
$date->add(\DateInterval::createFromDateString(sprintf('+%s days',$this->interval)));
} else {
$date->add(\DateInterval::createFromDateString(sprintf('+%s weeks',$this->interval)));
}
return $date;
}
function __construct($data) {
$interval = intval($data[1]);
if (is_integer($interval)) {
$this->interval = $data[1];
} else {
throw new \BadMethodCallException("interval is wrong or missing");
}
switch($data[2]) {
case DateTranslator::getInstance()->translate('Tage'):
$this->days_or_week = 0;
break;
case DateTranslator::getInstance()->translate('Wochen'):
$this->days_or_week = 1;
break;
default:
throw new \BadMethodCallException("days or weeks are missing");
}
}
}