20 $this->value = new \DateTime();
21 if ($date !==
null && $date !==
"")
25 $format = static::getFormat();
28 $parsedValue = date_parse_from_format($format, $date);
31 if ($parsedValue[
'error_count'] > 1)
34 current($parsedValue[
'errors']) !==
'Trailing data'
35 && current($parsedValue[
'errors']) !==
'Data missing'
42 $this->value->setDate($parsedValue[
'year'], $parsedValue[
'month'], $parsedValue[
'day']);
45 isset($parsedValue[
"relative"])
46 && isset($parsedValue[
"relative"][
"second"])
47 && $parsedValue[
"relative"][
"second"] != 0
50 $this->value->add(
new \DateInterval(
"PT".$parsedValue[
"relative"][
"second"].
"S"));
53 $this->value->setTime(0, 0, 0);
65 return $this->value->format($format);
98 public function add($interval)
100 $i = $this->tryToCreateIntervalByDesignators($interval);
103 $i = \DateInterval::createFromDateString($interval);
106 $this->value->add($i);
121 $this->value->setDate($year, $month, $day);
126 private function tryToCreateIntervalByDesignators($interval)
128 if (!is_string($interval) || strpos($interval,
' ') !==
false)
136 $intervalTmp = strtoupper($interval);
138 $firstChar = substr($intervalTmp, 0, 1);
139 if ($firstChar ===
"-")
142 $intervalTmp = substr($intervalTmp, 1);
143 $firstChar = substr($intervalTmp, 0, 1);
146 if ($firstChar !==
"P")
148 $intervalTmp =
"P".$intervalTmp;
150 $i = new \DateInterval($intervalTmp);
156 catch (\Exception $e)
170 return $this->value->getTimestamp();
181 return $this->value->diff($time->value);
193 $format = static::getFormat($culture);
194 return $this->
format($format);
216 static $defaultCulture =
null;
218 if($culture ===
null)
220 if($defaultCulture ===
null)
223 $defaultCulture = $context->getCulture();
225 $culture = $defaultCulture;
228 $format = static::getCultureFormat($culture);
230 return static::convertFormatToPhp($format);
242 return $culture->getDateFormat();
254 static $from = array(
275 $format = str_replace($from, $to, $format);
277 $tempFormat = $format;
278 $format = str_replace(
"HH",
"H", $format);
279 if ($tempFormat === $format)
281 $format = str_replace(
"H",
"h", $format);
284 $tempFormat = $format;
285 $format = str_replace(
"GG",
"G", $format);
286 if ($tempFormat === $format)
288 $format = str_replace(
"G",
"g", $format);
313 new static($time, $format);
334 $d->value = clone $datetime;
350 $d->value->setTimestamp($timestamp);
351 $d->value->setTime(0, 0, 0);
370 return $result[0]->getDate();