ILIAS  release_7 Revision v7.30-3-g800a261c036
DateFormat.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
5
11{
12 const DOT = '.';
13 const COMMA = ',';
14 const DASH = '-';
15 const SLASH = '/';
16 const SPACE = ' ';
17 const DAY = 'd';
18 const DAY_ORDINAL = 'jS';
19 const WEEKDAY = 'l';
20 const WEEKDAY_SHORT = 'D';
21 const WEEK = 'W';
22 const MONTH = 'm';
23 const MONTH_SPELLED = 'F';
25 const YEAR = 'Y';
26 const YEAR_TWO_DIG = 'y';
27
28 const TOKENS = [
44 ];
45
49 protected $format = [];
50
51 public function __construct(array $format)
52 {
53 $this->validateFormatElelements($format);
54 $this->format = $format;
55 }
56
57 public function validateFormatElelements(array $format)
58 {
59 foreach ($format as $entry) {
60 if (!in_array($entry, self::TOKENS)) {
61 throw new \InvalidArgumentException("not a valid token for date-format", 1);
62 }
63 }
64 }
65
70 public function toArray() : array
71 {
72 return $this->format;
73 }
74
79 public function toString() : string
80 {
81 return implode('', $this->format);
82 }
83}
An exception for terminatinating execution or to throw for unit testing.
toArray()
Get the elements of the format as array.
Definition: DateFormat.php:70
toString()
Get the format as string.
Definition: DateFormat.php:79
validateFormatElelements(array $format)
Definition: DateFormat.php:57