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