1 | <?php |
||
20 | class TwigExtensions |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * Formats the given time value to a timestring defined by the $pattern |
||
25 | * parameter. |
||
26 | * |
||
27 | * If the value is false (like null), an empty string is |
||
28 | * returned. Else, the value is tried to be parsed as datetime via the |
||
29 | * given pattern. If that fails, it is tried to be parsed with the pattern |
||
30 | * 'Y-m-d H:i:s'. If that fails, the value is returned unchanged. Else, it |
||
31 | * is returned formatted with the given pattern. The effect is to shorten |
||
32 | * 'Y-m-d H:i:s' to 'Y-m-d' for example. |
||
33 | * |
||
34 | * @param string $value |
||
35 | * the value to be formatted |
||
36 | * @param string $timezone |
||
37 | * the timezone of the value |
||
38 | * @param string $pattern |
||
39 | * the pattern with which the value is parsed and formatted |
||
40 | * |
||
41 | * @return string |
||
42 | * the formatted value |
||
43 | */ |
||
44 | 2 | protected function formatTime($value, $timezone, $pattern) |
|
59 | |||
60 | /** |
||
61 | * Gets a language name in the given language. |
||
62 | * |
||
63 | * @param string $language |
||
64 | * the language code of the desired language name |
||
65 | * |
||
66 | * @return string|null |
||
67 | * the language name in the given language or null if not available |
||
68 | */ |
||
69 | 1 | public function getLanguageName($language) |
|
77 | |||
78 | /** |
||
79 | * Formats a float to not display in scientific notation. |
||
80 | * |
||
81 | * @param float $float |
||
82 | * the float to format |
||
83 | * |
||
84 | * @return double|string |
||
85 | * the formated float |
||
86 | */ |
||
87 | 1 | public function formatFloat($float) |
|
104 | |||
105 | /** |
||
106 | * Formats the given value to a date of the format 'Y-m-d'. |
||
107 | * |
||
108 | * @param string $value |
||
109 | * the value, might be of the format 'Y-m-d H:i' or 'Y-m-d' |
||
110 | * @param boolean $isUTC |
||
111 | * whether the given value is in UTC |
||
112 | * |
||
113 | * @return string |
||
114 | * the formatted result or an empty string on null value |
||
115 | */ |
||
116 | 1 | public function formatDate($value, $isUTC) |
|
121 | |||
122 | /** |
||
123 | * Formats the given value to a date of the format 'Y-m-d H:i'. |
||
124 | * |
||
125 | * @param string $value |
||
126 | * the value, might be of the format 'Y-m-d H:i' |
||
127 | * @param boolean $isUTC |
||
128 | * whether the given value is in UTC |
||
129 | * |
||
130 | * @return string |
||
131 | * the formatted result or an empty string on null value |
||
132 | */ |
||
133 | 1 | public function formatDateTime($value, $isUTC) |
|
138 | |||
139 | } |
||
140 |