ILIAS
trunk Revision v11.0_alpha-3011-gc6b235a2e85
◀ ilDoc Overview
DateFormat.php
Go to the documentation of this file.
1
<?php
18
declare(strict_types=1);
19
20
namespace
ILIAS\Data\DateFormat
;
21
26
class
DateFormat
27
{
28
public
const
DOT
=
'.'
;
29
public
const
COMMA
=
','
;
30
public
const
DASH
=
'-'
;
31
public
const
SLASH
=
'/'
;
32
public
const
SPACE
=
' '
;
33
public
const
DAY
=
'd'
;
34
public
const
DAY_ORDINAL
=
'jS'
;
35
public
const
WEEKDAY
=
'l'
;
36
public
const
WEEKDAY_SHORT
=
'D'
;
37
public
const
WEEK
=
'W'
;
38
public
const
MONTH
=
'm'
;
39
public
const
MONTH_SPELLED
=
'F'
;
40
public
const
MONTH_SPELLED_SHORT
=
'M'
;
41
public
const
YEAR
=
'Y'
;
42
public
const
YEAR_TWO_DIG
=
'y'
;
43
public
const
HOURS12
=
'h'
;
44
public
const
HOURS24
=
'H'
;
45
public
const
MINUTES
=
'i'
;
46
public
const
SECONDS
=
's'
;
47
public
const
MERIDIEM
=
'a'
;
48
public
const
COLON
=
':'
;
49
50
public
const
TOKENS
= [
51
self::DOT
,
52
self::COMMA
,
53
self::DASH
,
54
self::SLASH
,
55
self::SPACE
,
56
self::DAY
,
57
self::DAY_ORDINAL
,
58
self::WEEKDAY
,
59
self::WEEKDAY_SHORT
,
60
self::WEEK
,
61
self::MONTH
,
62
self::MONTH_SPELLED
,
63
self::MONTH_SPELLED_SHORT
,
64
self::YEAR
,
65
self::YEAR_TWO_DIG
,
66
self::HOURS12
,
67
self::HOURS24
,
68
self::MINUTES
,
69
self::SECONDS
,
70
self::MERIDIEM
,
71
self::COLON
72
];
73
75
protected
array
$format
= [];
76
77
public
function
__construct
(array
$format
)
78
{
79
$this->
validateFormatElelements
($format);
80
$this->format =
$format
;
81
}
82
83
public
function
validateFormatElelements
(array
$format
): void
84
{
85
foreach
(
$format
as $entry) {
86
if
(!in_array($entry, self::TOKENS,
true
)) {
87
throw
new \InvalidArgumentException(
"not a valid token for date-format"
, 1);
88
}
89
}
90
}
91
96
public
function
toArray
(): array
97
{
98
return
$this->format
;
99
}
100
104
public
function
toString
(): string
105
{
106
return
implode(
''
, $this->format);
107
}
108
109
public
function
__toString
(): string
110
{
111
return
$this->
toString
();
112
}
113
114
public
function
applyTo
(\DateTimeImmutable
$datetime
): string
115
{
116
return
$datetime
->format($this->
toString
());
117
}
118
}
$datetime
$datetime
Definition:
LOMStructure.php:69
ILIAS\Data\DateFormat\DateFormat
A Date Format provides a format definition akin to PHP's date formatting options, but stores the sing...
Definition:
DateFormat.php:27
ILIAS\Data\DateFormat\DateFormat\SPACE
const SPACE
Definition:
DateFormat.php:32
ILIAS\Data\DateFormat\DateFormat\HOURS12
const HOURS12
Definition:
DateFormat.php:43
ILIAS\Data\DateFormat\DateFormat\MERIDIEM
const MERIDIEM
Definition:
DateFormat.php:47
ILIAS\Data\DateFormat\DateFormat\DAY_ORDINAL
const DAY_ORDINAL
Definition:
DateFormat.php:34
ILIAS\Data\DateFormat\DateFormat\COMMA
const COMMA
Definition:
DateFormat.php:29
ILIAS\Data\DateFormat\DateFormat\__toString
__toString()
Definition:
DateFormat.php:109
ILIAS\Data\DateFormat\DateFormat\TOKENS
const TOKENS
Definition:
DateFormat.php:50
ILIAS\Data\DateFormat\DateFormat\YEAR
const YEAR
Definition:
DateFormat.php:41
ILIAS\Data\DateFormat\DateFormat\$format
array $format
Definition:
DateFormat.php:75
ILIAS\Data\DateFormat\DateFormat\WEEK
const WEEK
Definition:
DateFormat.php:37
ILIAS\Data\DateFormat\DateFormat\MONTH_SPELLED_SHORT
const MONTH_SPELLED_SHORT
Definition:
DateFormat.php:40
ILIAS\Data\DateFormat\DateFormat\DASH
const DASH
Definition:
DateFormat.php:30
ILIAS\Data\DateFormat\DateFormat\HOURS24
const HOURS24
Definition:
DateFormat.php:44
ILIAS\Data\DateFormat\DateFormat\DAY
const DAY
Definition:
DateFormat.php:33
ILIAS\Data\DateFormat\DateFormat\__construct
__construct(array $format)
Definition:
DateFormat.php:77
ILIAS\Data\DateFormat\DateFormat\MINUTES
const MINUTES
Definition:
DateFormat.php:45
ILIAS\Data\DateFormat\DateFormat\COLON
const COLON
Definition:
DateFormat.php:48
ILIAS\Data\DateFormat\DateFormat\MONTH
const MONTH
Definition:
DateFormat.php:38
ILIAS\Data\DateFormat\DateFormat\MONTH_SPELLED
const MONTH_SPELLED
Definition:
DateFormat.php:39
ILIAS\Data\DateFormat\DateFormat\YEAR_TWO_DIG
const YEAR_TWO_DIG
Definition:
DateFormat.php:42
ILIAS\Data\DateFormat\DateFormat\WEEKDAY
const WEEKDAY
Definition:
DateFormat.php:35
ILIAS\Data\DateFormat\DateFormat\toArray
toArray()
Get the elements of the format as array.
Definition:
DateFormat.php:96
ILIAS\Data\DateFormat\DateFormat\SECONDS
const SECONDS
Definition:
DateFormat.php:46
ILIAS\Data\DateFormat\DateFormat\toString
toString()
Get the format as string.
Definition:
DateFormat.php:104
ILIAS\Data\DateFormat\DateFormat\validateFormatElelements
validateFormatElelements(array $format)
Definition:
DateFormat.php:83
ILIAS\Data\DateFormat\DateFormat\SLASH
const SLASH
Definition:
DateFormat.php:31
ILIAS\Data\DateFormat\DateFormat\applyTo
applyTo(\DateTimeImmutable $datetime)
Definition:
DateFormat.php:114
ILIAS\Data\DateFormat\DateFormat\DOT
const DOT
Definition:
DateFormat.php:28
ILIAS\Data\DateFormat\DateFormat\WEEKDAY_SHORT
const WEEKDAY_SHORT
Definition:
DateFormat.php:36
ILIAS\Data\DateFormat
Definition:
DateFormat.php:20
components
ILIAS
Data
src
DateFormat
DateFormat.php
Generated on Sat Oct 18 2025 23:02:42 for ILIAS by
1.9.4 (using
Doxyfile
)