ILIAS  release_7 Revision v7.30-3-g800a261c036
DateTimeTransformation.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3/* Copyright (c) 2020 Luka K. A. Stocker, Extended GPL, see docs/LICENSE */
4
6
11
20{
23
27 public function transform($from)
28 {
29 if ($from instanceof \DateTimeImmutable) {
30 return $from;
31 }
32
33 $formats = [
34 \DateTimeImmutable::ATOM,
35 \DateTimeImmutable::COOKIE,
36 \DateTimeImmutable::ISO8601,
37 \DateTimeImmutable::RFC822,
38 \DateTimeImmutable::RFC7231,
39 \DateTimeImmutable::RFC3339_EXTENDED
40 ];
41
42 if (is_string($from)) {
43 foreach ($formats as $format) {
44 $res = \DateTimeImmutable::createFromFormat($format, $from);
45 if ($res instanceof \DateTimeImmutable) {
46 return $res;
47 }
48 }
49 }
50
51 if (is_int($from) || is_float($from)) {
52 return new \DateTimeImmutable("@" . round($from));
53 }
54
56 sprintf('Value "%s" could not be transformed.', $from),
57 'no_valid_datetime',
58 $from
59 );
60 }
61}
An exception for terminatinating execution or to throw for unit testing.
Transform date format to DateTimeImmutable Please note:
transform($from)
Perform the transformation.Please use this for transformations. It's more performant than calling inv...
$formats
Definition: date.php:77
A transformation is a function from one datatype to another.
$format
Definition: metadata.php:218
foreach($_POST as $key=> $value) $res