aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/intl/Symfony/Component/Intl/DateFormatter')
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php46
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php59
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php46
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php46
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php356
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php62
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php62
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php61
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php64
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php30
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php48
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php143
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php64
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php48
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/TimeZoneTransformer.php99
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php64
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php50
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php631
18 files changed, 0 insertions, 1979 deletions
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php
deleted file mode 100644
index 1a9601d8..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php
+++ /dev/null
@@ -1,46 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for AM/PM markers format
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class AmPmTransformer extends Transformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 return $dateTime->format('A');
27 }
28
29 /**
30 * {@inheritDoc}
31 */
32 public function getReverseMatchingRegExp($length)
33 {
34 return 'AM|PM';
35 }
36
37 /**
38 * {@inheritDoc}
39 */
40 public function extractDateOptions($matched, $length)
41 {
42 return array(
43 'marker' => $matched
44 );
45 }
46}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php
deleted file mode 100644
index ee53a4e6..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php
+++ /dev/null
@@ -1,59 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for day of week format
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class DayOfWeekTransformer extends Transformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 $dayOfWeek = $dateTime->format('l');
27 switch ($length) {
28 case 4:
29 return $dayOfWeek;
30 case 5:
31 return $dayOfWeek[0];
32 default:
33 return substr($dayOfWeek, 0, 3);
34 }
35 }
36
37 /**
38 * {@inheritDoc}
39 */
40 public function getReverseMatchingRegExp($length)
41 {
42 switch ($length) {
43 case 4:
44 return 'Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday';
45 case 5:
46 return '[MTWFS]';
47 default:
48 return 'Mon|Tue|Wed|Thu|Fri|Sat|Sun';
49 }
50 }
51
52 /**
53 * {@inheritDoc}
54 */
55 public function extractDateOptions($matched, $length)
56 {
57 return array();
58 }
59}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php
deleted file mode 100644
index 2c33888c..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php
+++ /dev/null
@@ -1,46 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for day of year format
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class DayOfYearTransformer extends Transformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 $dayOfYear = $dateTime->format('z') + 1;
27
28 return $this->padLeft($dayOfYear, $length);
29 }
30
31 /**
32 * {@inheritDoc}
33 */
34 public function getReverseMatchingRegExp($length)
35 {
36 return '\d{'.$length.'}';
37 }
38
39 /**
40 * {@inheritDoc}
41 */
42 public function extractDateOptions($matched, $length)
43 {
44 return array();
45 }
46}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php
deleted file mode 100644
index 19d30e74..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php
+++ /dev/null
@@ -1,46 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for day format
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class DayTransformer extends Transformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 return $this->padLeft($dateTime->format('j'), $length);
27 }
28
29 /**
30 * {@inheritDoc}
31 */
32 public function getReverseMatchingRegExp($length)
33 {
34 return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
35 }
36
37 /**
38 * {@inheritDoc}
39 */
40 public function extractDateOptions($matched, $length)
41 {
42 return array(
43 'day' => (int) $matched,
44 );
45 }
46}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php
deleted file mode 100644
index b89db363..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php
+++ /dev/null
@@ -1,356 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14use Symfony\Component\Intl\Exception\NotImplementedException;
15use Symfony\Component\Intl\Globals\IntlGlobals;
16use Symfony\Component\Intl\DateFormatter\DateFormat\MonthTransformer;
17
18/**
19 * Parser and formatter for date formats
20 *
21 * @author Igor Wiedler <igor@wiedler.ch>
22 */
23class FullTransformer
24{
25 private $quoteMatch = "'(?:[^']+|'')*'";
26 private $implementedChars = 'MLydQqhDEaHkKmsz';
27 private $notImplementedChars = 'GYuwWFgecSAZvVW';
28 private $regExp;
29
30 /**
31 * @var Transformer[]
32 */
33 private $transformers;
34
35 private $pattern;
36 private $timezone;
37
38 /**
39 * Constructor
40 *
41 * @param string $pattern The pattern to be used to format and/or parse values
42 * @param string $timezone The timezone to perform the date/time calculations
43 */
44 public function __construct($pattern, $timezone)
45 {
46 $this->pattern = $pattern;
47 $this->timezone = $timezone;
48
49 $implementedCharsMatch = $this->buildCharsMatch($this->implementedChars);
50 $notImplementedCharsMatch = $this->buildCharsMatch($this->notImplementedChars);
51 $this->regExp = "/($this->quoteMatch|$implementedCharsMatch|$notImplementedCharsMatch)/";
52
53 $this->transformers = array(
54 'M' => new MonthTransformer(),
55 'L' => new MonthTransformer(),
56 'y' => new YearTransformer(),
57 'd' => new DayTransformer(),
58 'q' => new QuarterTransformer(),
59 'Q' => new QuarterTransformer(),
60 'h' => new Hour1201Transformer(),
61 'D' => new DayOfYearTransformer(),
62 'E' => new DayOfWeekTransformer(),
63 'a' => new AmPmTransformer(),
64 'H' => new Hour2400Transformer(),
65 'K' => new Hour1200Transformer(),
66 'k' => new Hour2401Transformer(),
67 'm' => new MinuteTransformer(),
68 's' => new SecondTransformer(),
69 'z' => new TimeZoneTransformer(),
70 );
71 }
72
73 /**
74 * Return the array of Transformer objects
75 *
76 * @return Transformer[] Associative array of Transformer objects (format char => Transformer)
77 */
78 public function getTransformers()
79 {
80 return $this->transformers;
81 }
82
83 /**
84 * Format a DateTime using ICU dateformat pattern
85 *
86 * @param \DateTime $dateTime A DateTime object to be used to generate the formatted value
87 *
88 * @return string The formatted value
89 */
90 public function format(\DateTime $dateTime)
91 {
92 $that = $this;
93
94 $formatted = preg_replace_callback($this->regExp, function($matches) use ($that, $dateTime) {
95 return $that->formatReplace($matches[0], $dateTime);
96 }, $this->pattern);
97
98 return $formatted;
99 }
100
101 /**
102 * Return the formatted ICU value for the matched date characters
103 *
104 * @param string $dateChars The date characters to be replaced with a formatted ICU value
105 * @param DateTime $dateTime A DateTime object to be used to generate the formatted value
106 *
107 * @return string The formatted value
108 *
109 * @throws NotImplementedException When it encounters a not implemented date character
110 */
111 public function formatReplace($dateChars, $dateTime)
112 {
113 $length = strlen($dateChars);
114
115 if ($this->isQuoteMatch($dateChars)) {
116 return $this->replaceQuoteMatch($dateChars);
117 }
118
119 if (isset($this->transformers[$dateChars[0]])) {
120 $transformer = $this->transformers[$dateChars[0]];
121
122 return $transformer->format($dateTime, $length);
123 }
124
125 // handle unimplemented characters
126 if (false !== strpos($this->notImplementedChars, $dateChars[0])) {
127 throw new NotImplementedException(sprintf("Unimplemented date character '%s' in format '%s'", $dateChars[0], $this->pattern));
128 }
129 }
130
131 /**
132 * Parse a pattern based string to a timestamp value
133 *
134 * @param \DateTime $dateTime A configured DateTime object to use to perform the date calculation
135 * @param string $value String to convert to a time value
136 *
137 * @return int The corresponding Unix timestamp
138 *
139 * @throws \InvalidArgumentException When the value can not be matched with pattern
140 */
141 public function parse(\DateTime $dateTime, $value)
142 {
143 $reverseMatchingRegExp = $this->getReverseMatchingRegExp($this->pattern);
144 $reverseMatchingRegExp = '/^'.$reverseMatchingRegExp.'$/';
145
146 $options = array();
147
148 if (preg_match($reverseMatchingRegExp, $value, $matches)) {
149 $matches = $this->normalizeArray($matches);
150
151 foreach ($this->transformers as $char => $transformer) {
152 if (isset($matches[$char])) {
153 $length = strlen($matches[$char]['pattern']);
154 $options = array_merge($options, $transformer->extractDateOptions($matches[$char]['value'], $length));
155 }
156 }
157
158 // reset error code and message
159 IntlGlobals::setError(IntlGlobals::U_ZERO_ERROR);
160
161 return $this->calculateUnixTimestamp($dateTime, $options);
162 }
163
164 // behave like the intl extension
165 IntlGlobals::setError(IntlGlobals::U_PARSE_ERROR, 'Date parsing failed');
166
167 return false;
168 }
169
170 /**
171 * Retrieve a regular expression to match with a formatted value.
172 *
173 * @param string $pattern The pattern to create the reverse matching regular expression
174 *
175 * @return string The reverse matching regular expression with named captures being formed by the
176 * transformer index in the $transformer array
177 */
178 public function getReverseMatchingRegExp($pattern)
179 {
180 $that = $this;
181
182 $escapedPattern = preg_quote($pattern, '/');
183
184 // ICU 4.8 recognizes slash ("/") in a value to be parsed as a dash ("-") and vice-versa
185 // when parsing a date/time value
186 $escapedPattern = preg_replace('/\\\[\-|\/]/', '[\/\-]', $escapedPattern);
187
188 $reverseMatchingRegExp = preg_replace_callback($this->regExp, function($matches) use ($that) {
189 $length = strlen($matches[0]);
190 $transformerIndex = $matches[0][0];
191
192 $dateChars = $matches[0];
193 if ($that->isQuoteMatch($dateChars)) {
194 return $that->replaceQuoteMatch($dateChars);
195 }
196
197 $transformers = $that->getTransformers();
198 if (isset($transformers[$transformerIndex])) {
199 $transformer = $transformers[$transformerIndex];
200 $captureName = str_repeat($transformerIndex, $length);
201
202 return "(?P<$captureName>".$transformer->getReverseMatchingRegExp($length).')';
203 }
204 }, $escapedPattern);
205
206 return $reverseMatchingRegExp;
207 }
208
209 /**
210 * Check if the first char of a string is a single quote
211 *
212 * @param string $quoteMatch The string to check
213 *
214 * @return Boolean true if matches, false otherwise
215 */
216 public function isQuoteMatch($quoteMatch)
217 {
218 return ("'" === $quoteMatch[0]);
219 }
220
221 /**
222 * Replaces single quotes at the start or end of a string with two single quotes
223 *
224 * @param string $quoteMatch The string to replace the quotes
225 *
226 * @return string A string with the single quotes replaced
227 */
228 public function replaceQuoteMatch($quoteMatch)
229 {
230 if (preg_match("/^'+$/", $quoteMatch)) {
231 return str_replace("''", "'", $quoteMatch);
232 }
233
234 return str_replace("''", "'", substr($quoteMatch, 1, -1));
235 }
236
237 /**
238 * Builds a chars match regular expression
239 *
240 * @param string $specialChars A string of chars to build the regular expression
241 *
242 * @return string The chars match regular expression
243 */
244 protected function buildCharsMatch($specialChars)
245 {
246 $specialCharsArray = str_split($specialChars);
247
248 $specialCharsMatch = implode('|', array_map(function($char) {
249 return $char.'+';
250 }, $specialCharsArray));
251
252 return $specialCharsMatch;
253 }
254
255 /**
256 * Normalize a preg_replace match array, removing the numeric keys and returning an associative array
257 * with the value and pattern values for the matched Transformer
258 *
259 * @param array $data
260 *
261 * @return array
262 */
263 protected function normalizeArray(array $data)
264 {
265 $ret = array();
266
267 foreach ($data as $key => $value) {
268 if (!is_string($key)) {
269 continue;
270 }
271
272 $ret[$key[0]] = array(
273 'value' => $value,
274 'pattern' => $key
275 );
276 }
277
278 return $ret;
279 }
280
281 /**
282 * Calculates the Unix timestamp based on the matched values by the reverse matching regular
283 * expression of parse()
284 *
285 * @param \DateTime $dateTime The DateTime object to be used to calculate the timestamp
286 * @param array $options An array with the matched values to be used to calculate the timestamp
287 *
288 * @return Boolean|int The calculated timestamp or false if matched date is invalid
289 */
290 protected function calculateUnixTimestamp(\DateTime $dateTime, array $options)
291 {
292 $options = $this->getDefaultValueForOptions($options);
293
294 $year = $options['year'];
295 $month = $options['month'];
296 $day = $options['day'];
297 $hour = $options['hour'];
298 $hourInstance = $options['hourInstance'];
299 $minute = $options['minute'];
300 $second = $options['second'];
301 $marker = $options['marker'];
302 $timezone = $options['timezone'];
303
304 // If month is false, return immediately (intl behavior)
305 if (false === $month) {
306 IntlGlobals::setError(IntlGlobals::U_PARSE_ERROR, 'Date parsing failed');
307
308 return false;
309 }
310
311 // Normalize hour
312 if ($hourInstance instanceof HourTransformer) {
313 $hour = $hourInstance->normalizeHour($hour, $marker);
314 }
315
316 // Set the timezone if different from the default one
317 if (null !== $timezone && $timezone !== $this->timezone) {
318 $dateTime->setTimezone(new \DateTimeZone($timezone));
319 }
320
321 // Normalize yy year
322 preg_match_all($this->regExp, $this->pattern, $matches);
323 if (in_array('yy', $matches[0])) {
324 $dateTime->setTimestamp(time());
325 $year = $year > $dateTime->format('y') + 20 ? 1900 + $year : 2000 + $year;
326 }
327
328 $dateTime->setDate($year, $month, $day);
329 $dateTime->setTime($hour, $minute, $second);
330
331 return $dateTime->getTimestamp();
332 }
333
334 /**
335 * Add sensible default values for missing items in the extracted date/time options array. The values
336 * are base in the beginning of the Unix era
337 *
338 * @param array $options
339 *
340 * @return array
341 */
342 private function getDefaultValueForOptions(array $options)
343 {
344 return array(
345 'year' => isset($options['year']) ? $options['year'] : 1970,
346 'month' => isset($options['month']) ? $options['month'] : 1,
347 'day' => isset($options['day']) ? $options['day'] : 1,
348 'hour' => isset($options['hour']) ? $options['hour'] : 0,
349 'hourInstance' => isset($options['hourInstance']) ? $options['hourInstance'] : null,
350 'minute' => isset($options['minute']) ? $options['minute'] : 0,
351 'second' => isset($options['second']) ? $options['second'] : 0,
352 'marker' => isset($options['marker']) ? $options['marker'] : null,
353 'timezone' => isset($options['timezone']) ? $options['timezone'] : null,
354 );
355 }
356}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php
deleted file mode 100644
index 8c8f5ef4..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php
+++ /dev/null
@@ -1,62 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for 12 hour format (0-11)
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class Hour1200Transformer extends HourTransformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 $hourOfDay = $dateTime->format('g');
27 $hourOfDay = '12' == $hourOfDay ? '0' : $hourOfDay;
28
29 return $this->padLeft($hourOfDay, $length);
30 }
31
32 /**
33 * {@inheritDoc}
34 */
35 public function normalizeHour($hour, $marker = null)
36 {
37 if ('PM' === $marker) {
38 $hour += 12;
39 }
40
41 return $hour;
42 }
43
44 /**
45 * {@inheritDoc}
46 */
47 public function getReverseMatchingRegExp($length)
48 {
49 return '\d{1,2}';
50 }
51
52 /**
53 * {@inheritDoc}
54 */
55 public function extractDateOptions($matched, $length)
56 {
57 return array(
58 'hour' => (int) $matched,
59 'hourInstance' => $this
60 );
61 }
62}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php
deleted file mode 100644
index a8c43702..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php
+++ /dev/null
@@ -1,62 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for 12 hour format (1-12)
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class Hour1201Transformer extends HourTransformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 return $this->padLeft($dateTime->format('g'), $length);
27 }
28
29 /**
30 * {@inheritDoc}
31 */
32 public function normalizeHour($hour, $marker = null)
33 {
34 if ('PM' !== $marker && 12 === $hour) {
35 $hour = 0;
36 } elseif ('PM' === $marker && 12 !== $hour) {
37 // If PM and hour is not 12 (1-12), sum 12 hour
38 $hour += 12;
39 }
40
41 return $hour;
42 }
43
44 /**
45 * {@inheritDoc}
46 */
47 public function getReverseMatchingRegExp($length)
48 {
49 return '\d{1,2}';
50 }
51
52 /**
53 * {@inheritDoc}
54 */
55 public function extractDateOptions($matched, $length)
56 {
57 return array(
58 'hour' => (int) $matched,
59 'hourInstance' => $this
60 );
61 }
62}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php
deleted file mode 100644
index 8f22da13..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php
+++ /dev/null
@@ -1,61 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for 24 hour format (0-23)
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class Hour2400Transformer extends HourTransformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 return $this->padLeft($dateTime->format('G'), $length);
27 }
28
29 /**
30 * {@inheritDoc}
31 */
32 public function normalizeHour($hour, $marker = null)
33 {
34 if ('AM' == $marker) {
35 $hour = 0;
36 } elseif ('PM' == $marker) {
37 $hour = 12;
38 }
39
40 return $hour;
41 }
42
43 /**
44 * {@inheritDoc}
45 */
46 public function getReverseMatchingRegExp($length)
47 {
48 return '\d{1,2}';
49 }
50
51 /**
52 * {@inheritDoc}
53 */
54 public function extractDateOptions($matched, $length)
55 {
56 return array(
57 'hour' => (int) $matched,
58 'hourInstance' => $this
59 );
60 }
61}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php
deleted file mode 100644
index b0f486b9..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php
+++ /dev/null
@@ -1,64 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for 24 hour format (1-24)
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class Hour2401Transformer extends HourTransformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 $hourOfDay = $dateTime->format('G');
27 $hourOfDay = ('0' == $hourOfDay) ? '24' : $hourOfDay;
28
29 return $this->padLeft($hourOfDay, $length);
30 }
31
32 /**
33 * {@inheritDoc}
34 */
35 public function normalizeHour($hour, $marker = null)
36 {
37 if ((null === $marker && 24 === $hour) || 'AM' == $marker) {
38 $hour = 0;
39 } elseif ('PM' == $marker) {
40 $hour = 12;
41 }
42
43 return $hour;
44 }
45
46 /**
47 * {@inheritDoc}
48 */
49 public function getReverseMatchingRegExp($length)
50 {
51 return '\d{1,2}';
52 }
53
54 /**
55 * {@inheritDoc}
56 */
57 public function extractDateOptions($matched, $length)
58 {
59 return array(
60 'hour' => (int) $matched,
61 'hourInstance' => $this
62 );
63 }
64}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php
deleted file mode 100644
index 51097d92..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php
+++ /dev/null
@@ -1,30 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Base class for hour transformers
16 *
17 * @author Eriksen Costa <eriksen.costa@infranology.com.br>
18 */
19abstract class HourTransformer extends Transformer
20{
21 /**
22 * Returns a normalized hour value suitable for the hour transformer type
23 *
24 * @param int $hour The hour value
25 * @param string $marker An optional AM/PM marker
26 *
27 * @return int The normalized hour value
28 */
29 abstract public function normalizeHour($hour, $marker = null);
30}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php
deleted file mode 100644
index b48de292..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php
+++ /dev/null
@@ -1,48 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for minute format
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class MinuteTransformer extends Transformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 $minuteOfHour = (int) $dateTime->format('i');
27
28 return $this->padLeft($minuteOfHour, $length);
29 }
30
31 /**
32 * {@inheritDoc}
33 */
34 public function getReverseMatchingRegExp($length)
35 {
36 return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
37 }
38
39 /**
40 * {@inheritDoc}
41 */
42 public function extractDateOptions($matched, $length)
43 {
44 return array(
45 'minute' => (int) $matched,
46 );
47 }
48}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php
deleted file mode 100644
index 30c15af7..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php
+++ /dev/null
@@ -1,143 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for month format
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class MonthTransformer extends Transformer
20{
21 /**
22 * @var array
23 */
24 protected static $months = array(
25 'January',
26 'February',
27 'March',
28 'April',
29 'May',
30 'June',
31 'July',
32 'August',
33 'September',
34 'October',
35 'November',
36 'December'
37 );
38
39 /**
40 * Short months names (first 3 letters)
41 * @var array
42 */
43 protected static $shortMonths = array();
44
45 /**
46 * Flipped $months array, $name => $index
47 * @var array
48 */
49 protected static $flippedMonths = array();
50
51 /**
52 * Flipped $shortMonths array, $name => $index
53 * @var array
54 */
55 protected static $flippedShortMonths = array();
56
57 /**
58 * Constructor
59 */
60 public function __construct()
61 {
62 if (0 === count(self::$shortMonths)) {
63 self::$shortMonths = array_map(function($month) {
64 return substr($month, 0, 3);
65 }, self::$months);
66
67 self::$flippedMonths = array_flip(self::$months);
68 self::$flippedShortMonths = array_flip(self::$shortMonths);
69 }
70 }
71
72 /**
73 * {@inheritDoc}
74 */
75 public function format(\DateTime $dateTime, $length)
76 {
77 $matchLengthMap = array(
78 1 => 'n',
79 2 => 'm',
80 3 => 'M',
81 4 => 'F',
82 );
83
84 if (isset($matchLengthMap[$length])) {
85 return $dateTime->format($matchLengthMap[$length]);
86 }
87
88 if (5 === $length) {
89 return substr($dateTime->format('M'), 0, 1);
90 }
91
92 return $this->padLeft($dateTime->format('m'), $length);
93 }
94
95 /**
96 * {@inheritDoc}
97 */
98 public function getReverseMatchingRegExp($length)
99 {
100 switch ($length) {
101 case 1:
102 $regExp = '\d{1,2}';
103 break;
104 case 3:
105 $regExp = implode('|', self::$shortMonths);
106 break;
107 case 4:
108 $regExp = implode('|', self::$months);
109 break;
110 case 5:
111 $regExp = '[JFMASOND]';
112 break;
113 default:
114 $regExp = '\d{'.$length.'}';
115 break;
116 }
117
118 return $regExp;
119 }
120
121 /**
122 * {@inheritDoc}
123 */
124 public function extractDateOptions($matched, $length)
125 {
126 if (!is_numeric($matched)) {
127 if (3 === $length) {
128 $matched = self::$flippedShortMonths[$matched] + 1;
129 } elseif (4 === $length) {
130 $matched = self::$flippedMonths[$matched] + 1;
131 } elseif (5 === $length) {
132 // IntlDateFormatter::parse() always returns false for MMMMM or LLLLL
133 $matched = false;
134 }
135 } else {
136 $matched = (int) $matched;
137 }
138
139 return array(
140 'month' => $matched,
141 );
142 }
143}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php
deleted file mode 100644
index 8e83dc75..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php
+++ /dev/null
@@ -1,64 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for quarter format
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class QuarterTransformer extends Transformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 $month = (int) $dateTime->format('n');
27 $quarter = (int) floor(($month - 1) / 3) + 1;
28 switch ($length) {
29 case 1:
30 case 2:
31 return $this->padLeft($quarter, $length);
32 case 3:
33 return 'Q'.$quarter;
34 default:
35 $map = array(1 => '1st quarter', 2 => '2nd quarter', 3 => '3rd quarter', 4 => '4th quarter');
36
37 return $map[$quarter];
38 }
39 }
40
41 /**
42 * {@inheritDoc}
43 */
44 public function getReverseMatchingRegExp($length)
45 {
46 switch ($length) {
47 case 1:
48 case 2:
49 return '\d{'.$length.'}';
50 case 3:
51 return 'Q\d';
52 default:
53 return '(?:1st|2nd|3rd|4th) quarter';
54 }
55 }
56
57 /**
58 * {@inheritDoc}
59 */
60 public function extractDateOptions($matched, $length)
61 {
62 return array();
63 }
64}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php
deleted file mode 100644
index ccbcdb41..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php
+++ /dev/null
@@ -1,48 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for the second format
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class SecondTransformer extends Transformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 $secondOfMinute = (int) $dateTime->format('s');
27
28 return $this->padLeft($secondOfMinute, $length);
29 }
30
31 /**
32 * {@inheritDoc}
33 */
34 public function getReverseMatchingRegExp($length)
35 {
36 return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
37 }
38
39 /**
40 * {@inheritDoc}
41 */
42 public function extractDateOptions($matched, $length)
43 {
44 return array(
45 'second' => (int) $matched,
46 );
47 }
48}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/TimeZoneTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/TimeZoneTransformer.php
deleted file mode 100644
index 7d74bd36..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/TimeZoneTransformer.php
+++ /dev/null
@@ -1,99 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14use Symfony\Component\Intl\Exception\NotImplementedException;
15
16/**
17 * Parser and formatter for time zone format
18 *
19 * @author Igor Wiedler <igor@wiedler.ch>
20 */
21class TimeZoneTransformer extends Transformer
22{
23 /**
24 * {@inheritDoc}
25 *
26 * @throws NotImplementedException When time zone is different than UTC or GMT (Etc/GMT)
27 */
28 public function format(\DateTime $dateTime, $length)
29 {
30 $timeZone = substr($dateTime->getTimezone()->getName(), 0, 3);
31
32 if (!in_array($timeZone, array('Etc', 'UTC'))) {
33 throw new NotImplementedException('Time zone different than GMT or UTC is not supported as a formatting output.');
34 }
35
36 // From ICU >= 4.8, the zero offset is not more used, example: GMT instead of GMT+00:00
37 $format = (0 !== (int) $dateTime->format('O')) ? '\G\M\TP' : '\G\M\T';
38
39 return $dateTime->format($format);
40 }
41
42 /**
43 * {@inheritDoc}
44 */
45 public function getReverseMatchingRegExp($length)
46 {
47 return 'GMT[+-]\d{2}:?\d{2}';
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 public function extractDateOptions($matched, $length)
54 {
55 return array(
56 'timezone' => self::getEtcTimeZoneId($matched)
57 );
58 }
59
60 /**
61 * Get an Etc/GMT timezone identifier for the specified timezone
62 *
63 * The PHP documentation for timezones states to not use the 'Other' time zones because them exists
64 * "for backwards compatibility". However all Etc/GMT time zones are in the tz database 'etcetera' file,
65 * which indicates they are not deprecated (neither are old names).
66 *
67 * Only GMT, Etc/Universal, Etc/Zulu, Etc/Greenwich, Etc/GMT-0, Etc/GMT+0 and Etc/GMT0 are old names and
68 * are linked to Etc/GMT or Etc/UTC.
69 *
70 * @param string $formattedTimeZone A GMT timezone string (GMT-03:00, e.g.)
71 *
72 * @return string A timezone identifier
73 *
74 * @see http://php.net/manual/en/timezones.others.php
75 * @see http://www.twinsun.com/tz/tz-link.htm
76 *
77 * @throws NotImplementedException When the GMT time zone have minutes offset different than zero
78 * @throws \InvalidArgumentException When the value can not be matched with pattern
79 */
80 public static function getEtcTimeZoneId($formattedTimeZone)
81 {
82 if (preg_match('/GMT(?P<signal>[+-])(?P<hours>\d{2}):?(?P<minutes>\d{2})/', $formattedTimeZone, $matches)) {
83 $hours = (int) $matches['hours'];
84 $minutes = (int) $matches['minutes'];
85 $signal = $matches['signal'] == '-' ? '+' : '-';
86
87 if (0 < $minutes) {
88 throw new NotImplementedException(sprintf(
89 'It is not possible to use a GMT time zone with minutes offset different than zero (0). GMT time zone tried: %s.',
90 $formattedTimeZone
91 ));
92 }
93
94 return 'Etc/GMT'.($hours !== 0 ? $signal.$hours : '');
95 }
96
97 throw new \InvalidArgumentException('The GMT time zone \'%s\' does not match with the supported formats GMT[+-]HH:MM or GMT[+-]HHMM.');
98 }
99}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php
deleted file mode 100644
index 0e67f8ae..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php
+++ /dev/null
@@ -1,64 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for date formats
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19abstract class Transformer
20{
21 /**
22 * Format a value using a configured DateTime as date/time source
23 *
24 *
25 * @param \DateTime $dateTime A DateTime object to be used to generate the formatted value
26 * @param int $length The formatted value string length
27 *
28 * @return string The formatted value
29 */
30 abstract public function format(\DateTime $dateTime, $length);
31
32 /**
33 * Returns a reverse matching regular expression of a string generated by format()
34 *
35 * @param int $length The length of the value to be reverse matched
36 *
37 * @return string The reverse matching regular expression
38 */
39 abstract public function getReverseMatchingRegExp($length);
40
41 /**
42 * Extract date options from a matched value returned by the processing of the reverse matching
43 * regular expression
44 *
45 * @param string $matched The matched value
46 * @param int $length The length of the Transformer pattern string
47 *
48 * @return array An associative array
49 */
50 abstract public function extractDateOptions($matched, $length);
51
52 /**
53 * Pad a string with zeros to the left
54 *
55 * @param string $value The string to be padded
56 * @param int $length The length to pad
57 *
58 * @return string The padded string
59 */
60 protected function padLeft($value, $length)
61 {
62 return str_pad($value, $length, '0', STR_PAD_LEFT);
63 }
64}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php
deleted file mode 100644
index c3bd699d..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php
+++ /dev/null
@@ -1,50 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for year format
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19class YearTransformer extends Transformer
20{
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 if (2 === $length) {
27 return $dateTime->format('y');
28 }
29
30 return $this->padLeft($dateTime->format('Y'), $length);
31 }
32
33 /**
34 * {@inheritDoc}
35 */
36 public function getReverseMatchingRegExp($length)
37 {
38 return 2 === $length ? '\d{2}' : '\d{4}';
39 }
40
41 /**
42 * {@inheritDoc}
43 */
44 public function extractDateOptions($matched, $length)
45 {
46 return array(
47 'year' => (int) $matched,
48 );
49 }
50}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php b/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php
deleted file mode 100644
index 33a499a8..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php
+++ /dev/null
@@ -1,631 +0,0 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\DateFormatter;
13
14use Symfony\Component\Intl\Globals\IntlGlobals;
15use Symfony\Component\Intl\DateFormatter\DateFormat\FullTransformer;
16use Symfony\Component\Intl\Exception\MethodNotImplementedException;
17use Symfony\Component\Intl\Exception\MethodArgumentNotImplementedException;
18use Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException;
19use Symfony\Component\Intl\Locale\Locale;
20
21/**
22 * Replacement for PHP's native {@link \IntlDateFormatter} class.
23 *
24 * The only methods currently supported in this class are:
25 *
26 * - {@link __construct}
27 * - {@link create}
28 * - {@link format}
29 * - {@link getCalendar}
30 * - {@link getDateType}
31 * - {@link getErrorCode}
32 * - {@link getErrorMessage}
33 * - {@link getLocale}
34 * - {@link getPattern}
35 * - {@link getTimeType}
36 * - {@link getTimeZoneId}
37 * - {@link isLenient}
38 * - {@link parse}
39 * - {@link setLenient}
40 * - {@link setPattern}
41 * - {@link setTimeZoneId}
42 * - {@link setTimeZone}
43 *
44 * @author Igor Wiedler <igor@wiedler.ch>
45 * @author Bernhard Schussek <bschussek@gmail.com>
46 */
47class IntlDateFormatter
48{
49 /**
50 * The error code from the last operation
51 *
52 * @var integer
53 */
54 protected $errorCode = IntlGlobals::U_ZERO_ERROR;
55
56 /**
57 * The error message from the last operation
58 *
59 * @var string
60 */
61 protected $errorMessage = 'U_ZERO_ERROR';
62
63 /* date/time format types */
64 const NONE = -1;
65 const FULL = 0;
66 const LONG = 1;
67 const MEDIUM = 2;
68 const SHORT = 3;
69
70 /* calendar formats */
71 const TRADITIONAL = 0;
72 const GREGORIAN = 1;
73
74 /**
75 * Patterns used to format the date when no pattern is provided
76 *
77 * @var array
78 */
79 private $defaultDateFormats = array(
80 self::NONE => '',
81 self::FULL => 'EEEE, LLLL d, y',
82 self::LONG => 'LLLL d, y',
83 self::MEDIUM => 'LLL d, y',
84 self::SHORT => 'M/d/yy',
85 );
86
87 /**
88 * Patterns used to format the time when no pattern is provided
89 *
90 * @var array
91 */
92 private $defaultTimeFormats = array(
93 self::FULL => 'h:mm:ss a zzzz',
94 self::LONG => 'h:mm:ss a z',
95 self::MEDIUM => 'h:mm:ss a',
96 self::SHORT => 'h:mm a',
97 );
98
99 /**
100 * @var int
101 */
102 private $datetype;
103
104 /**
105 * @var int
106 */
107 private $timetype;
108
109 /**
110 * @var string
111 */
112 private $pattern;
113
114 /**
115 * @var \DateTimeZone
116 */
117 private $dateTimeZone;
118
119 /**
120 * @var Boolean
121 */
122 private $unitializedTimeZoneId = false;
123
124 /**
125 * @var string
126 */
127 private $timeZoneId;
128
129 /**
130 * Constructor
131 *
132 * @param string $locale The locale code. The only currently supported locale is "en".
133 * @param int $datetype Type of date formatting, one of the format type constants
134 * @param int $timetype Type of time formatting, one of the format type constants
135 * @param string $timezone Timezone identifier
136 * @param int $calendar Calendar to use for formatting or parsing. The only currently
137 * supported value is IntlDateFormatter::GREGORIAN.
138 * @param string $pattern Optional pattern to use when formatting
139 *
140 * @see http://www.php.net/manual/en/intldateformatter.create.php
141 * @see http://userguide.icu-project.org/formatparse/datetime
142 *
143 * @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
144 * @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
145 */
146 public function __construct($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null)
147 {
148 if ('en' !== $locale) {
149 throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
150 }
151
152 if (self::GREGORIAN !== $calendar) {
153 throw new MethodArgumentValueNotImplementedException(__METHOD__, 'calendar', $calendar, 'Only the GREGORIAN calendar is supported');
154 }
155
156 $this->datetype = $datetype;
157 $this->timetype = $timetype;
158
159 $this->setPattern($pattern);
160 $this->setTimeZoneId($timezone);
161 }
162
163 /**
164 * Static constructor
165 *
166 * @param string $locale The locale code. The only currently supported locale is "en".
167 * @param int $datetype Type of date formatting, one of the format type constants
168 * @param int $timetype Type of time formatting, one of the format type constants
169 * @param string $timezone Timezone identifier
170 * @param int $calendar Calendar to use for formatting or parsing; default is Gregorian.
171 * One of the calendar constants.
172 * @param string $pattern Optional pattern to use when formatting
173 *
174 * @return IntlDateFormatter
175 *
176 * @see http://www.php.net/manual/en/intldateformatter.create.php
177 * @see http://userguide.icu-project.org/formatparse/datetime
178 *
179 * @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
180 * @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
181 */
182 public static function create($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null)
183 {
184 return new self($locale, $datetype, $timetype, $timezone, $calendar, $pattern);
185 }
186
187 /**
188 * Format the date/time value (timestamp) as a string
189 *
190 * @param integer|\DateTime $timestamp The timestamp to format. \DateTime objects
191 * are supported as of PHP 5.3.4.
192 *
193 * @return string|Boolean The formatted value or false if formatting failed.
194 *
195 * @see http://www.php.net/manual/en/intldateformatter.format.php
196 *
197 * @throws MethodArgumentValueNotImplementedException If one of the formatting characters is not implemented
198 */
199 public function format($timestamp)
200 {
201 // intl allows timestamps to be passed as arrays - we don't
202 if (is_array($timestamp)) {
203 $message = version_compare(PHP_VERSION, '5.3.4', '>=') ?
204 'Only integer unix timestamps and DateTime objects are supported' :
205 'Only integer unix timestamps are supported';
206
207 throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, $message);
208 }
209
210 // behave like the intl extension
211 $argumentError = null;
212 if (version_compare(PHP_VERSION, '5.3.4', '<') && !is_int($timestamp)) {
213 $argumentError = 'datefmt_format: takes either an array or an integer timestamp value ';
214 } elseif (version_compare(PHP_VERSION, '5.3.4', '>=') && !is_int($timestamp) && !$timestamp instanceof \DateTime) {
215 $argumentError = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object';
216 if (version_compare(PHP_VERSION, '5.5.0-dev', '>=') && !is_int($timestamp)) {
217 $argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $timestamp);
218 }
219 }
220
221 if (null !== $argumentError) {
222 IntlGlobals::setError(IntlGlobals::U_ILLEGAL_ARGUMENT_ERROR, $argumentError);
223 $this->errorCode = IntlGlobals::getErrorCode();
224 $this->errorMessage = IntlGlobals::getErrorMessage();
225
226 return false;
227 }
228
229 // As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances
230 if (version_compare(PHP_VERSION, '5.3.4', '>=') && $timestamp instanceof \DateTime) {
231 $timestamp = $timestamp->getTimestamp();
232 }
233
234 $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
235 $formatted = $transformer->format($this->createDateTime($timestamp));
236
237 // behave like the intl extension
238 IntlGlobals::setError(IntlGlobals::U_ZERO_ERROR);
239 $this->errorCode = IntlGlobals::getErrorCode();
240 $this->errorMessage = IntlGlobals::getErrorMessage();
241
242 return $formatted;
243 }
244
245 /**
246 * Not supported. Formats an object
247 *
248 * @param object $object
249 * @param mixed $format
250 * @param string $locale
251 *
252 * @return string The formatted value
253 *
254 * @see http://www.php.net/manual/en/intldateformatter.formatobject.php
255 *
256 * @throws MethodNotImplementedException
257 */
258 public function formatObject($object, $format = null, $locale = null)
259 {
260 throw new MethodNotImplementedException(__METHOD__);
261 }
262
263 /**
264 * Returns the formatter's calendar
265 *
266 * @return int The calendar being used by the formatter. Currently always returns
267 * IntlDateFormatter::GREGORIAN.
268 *
269 * @see http://www.php.net/manual/en/intldateformatter.getcalendar.php
270 */
271 public function getCalendar()
272 {
273 return self::GREGORIAN;
274 }
275
276 /**
277 * Not supported. Returns the formatter's calendar object
278 *
279 * @return object The calendar's object being used by the formatter
280 *
281 * @see http://www.php.net/manual/en/intldateformatter.getcalendarobject.php
282 *
283 * @throws MethodNotImplementedException
284 */
285 public function getCalendarObject()
286 {
287 throw new MethodNotImplementedException(__METHOD__);
288 }
289
290 /**
291 * Returns the formatter's datetype
292 *
293 * @return int The current value of the formatter
294 *
295 * @see http://www.php.net/manual/en/intldateformatter.getdatetype.php
296 */
297 public function getDateType()
298 {
299 return $this->datetype;
300 }
301
302 /**
303 * Returns formatter's last error code. Always returns the U_ZERO_ERROR class constant value
304 *
305 * @return int The error code from last formatter call
306 *
307 * @see http://www.php.net/manual/en/intldateformatter.geterrorcode.php
308 */
309 public function getErrorCode()
310 {
311 return $this->errorCode;
312 }
313
314 /**
315 * Returns formatter's last error message. Always returns the U_ZERO_ERROR_MESSAGE class constant value
316 *
317 * @return string The error message from last formatter call
318 *
319 * @see http://www.php.net/manual/en/intldateformatter.geterrormessage.php
320 */
321 public function getErrorMessage()
322 {
323 return $this->errorMessage;
324 }
325
326 /**
327 * Returns the formatter's locale
328 *
329 * @param int $type Not supported. The locale name type to return (Locale::VALID_LOCALE or Locale::ACTUAL_LOCALE)
330 *
331 * @return string The locale used to create the formatter. Currently always
332 * returns "en".
333 *
334 * @see http://www.php.net/manual/en/intldateformatter.getlocale.php
335 */
336 public function getLocale($type = Locale::ACTUAL_LOCALE)
337 {
338 return 'en';
339 }
340
341 /**
342 * Returns the formatter's pattern
343 *
344 * @return string The pattern string used by the formatter
345 *
346 * @see http://www.php.net/manual/en/intldateformatter.getpattern.php
347 */
348 public function getPattern()
349 {
350 return $this->pattern;
351 }
352
353 /**
354 * Returns the formatter's time type
355 *
356 * @return string The time type used by the formatter
357 *
358 * @see http://www.php.net/manual/en/intldateformatter.gettimetype.php
359 */
360 public function getTimeType()
361 {
362 return $this->timetype;
363 }
364
365 /**
366 * Returns the formatter's timezone identifier
367 *
368 * @return string The timezone identifier used by the formatter
369 *
370 * @see http://www.php.net/manual/en/intldateformatter.gettimezoneid.php
371 */
372 public function getTimeZoneId()
373 {
374 if (!$this->unitializedTimeZoneId) {
375 return $this->timeZoneId;
376 }
377
378 // In PHP 5.5 default timezone depends on `date_default_timezone_get()` method
379 if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) {
380 return date_default_timezone_get();
381 }
382
383 return null;
384 }
385
386 /**
387 * Not supported. Returns the formatter's timezone
388 *
389 * @return mixed The timezone used by the formatter
390 *
391 * @see http://www.php.net/manual/en/intldateformatter.gettimezone.php
392 *
393 * @throws MethodNotImplementedException
394 */
395 public function getTimeZone()
396 {
397 throw new MethodNotImplementedException(__METHOD__);
398 }
399
400 /**
401 * Returns whether the formatter is lenient
402 *
403 * @return Boolean Currently always returns false.
404 *
405 * @see http://www.php.net/manual/en/intldateformatter.islenient.php
406 *
407 * @throws MethodNotImplementedException
408 */
409 public function isLenient()
410 {
411 return false;
412 }
413
414 /**
415 * Not supported. Parse string to a field-based time value
416 *
417 * @param string $value String to convert to a time value
418 * @param int $position Position at which to start the parsing in $value (zero-based).
419 * If no error occurs before $value is consumed, $parse_pos will
420 * contain -1 otherwise it will contain the position at which parsing
421 * ended. If $parse_pos > strlen($value), the parse fails immediately.
422 *
423 * @return string Localtime compatible array of integers: contains 24 hour clock value in tm_hour field
424 *
425 * @see http://www.php.net/manual/en/intldateformatter.localtime.php
426 *
427 * @throws MethodNotImplementedException
428 */
429 public function localtime($value, &$position = 0)
430 {
431 throw new MethodNotImplementedException(__METHOD__);
432 }
433
434 /**
435 * Parse string to a timestamp value
436 *
437 * @param string $value String to convert to a time value
438 * @param int $position Not supported. Position at which to start the parsing in $value (zero-based).
439 * If no error occurs before $value is consumed, $parse_pos will
440 * contain -1 otherwise it will contain the position at which parsing
441 * ended. If $parse_pos > strlen($value), the parse fails immediately.
442 *
443 * @return string Parsed value as a timestamp
444 *
445 * @see http://www.php.net/manual/en/intldateformatter.parse.php
446 *
447 * @throws MethodArgumentNotImplementedException When $position different than null, behavior not implemented
448 */
449 public function parse($value, &$position = null)
450 {
451 // We don't calculate the position when parsing the value
452 if (null !== $position) {
453 throw new MethodArgumentNotImplementedException(__METHOD__, 'position');
454 }
455
456 $dateTime = $this->createDateTime(0);
457 $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
458
459 $timestamp = $transformer->parse($dateTime, $value);
460
461 // behave like the intl extension. FullTransformer::parse() set the proper error
462 $this->errorCode = IntlGlobals::getErrorCode();
463 $this->errorMessage = IntlGlobals::getErrorMessage();
464
465 return $timestamp;
466 }
467
468 /**
469 * Not supported. Set the formatter's calendar
470 *
471 * @param string $calendar The calendar to use. Default is IntlDateFormatter::GREGORIAN.
472 *
473 * @return Boolean true on success or false on failure
474 *
475 * @see http://www.php.net/manual/en/intldateformatter.setcalendar.php
476 *
477 * @throws MethodNotImplementedException
478 */
479 public function setCalendar($calendar)
480 {
481 throw new MethodNotImplementedException(__METHOD__);
482 }
483
484 /**
485 * Set the leniency of the parser
486 *
487 * Define if the parser is strict or lenient in interpreting inputs that do not match the pattern
488 * exactly. Enabling lenient parsing allows the parser to accept otherwise flawed date or time
489 * patterns, parsing as much as possible to obtain a value. Extra space, unrecognized tokens, or
490 * invalid values ("February 30th") are not accepted.
491 *
492 * @param Boolean $lenient Sets whether the parser is lenient or not. Currently
493 * only false (strict) is supported.
494 *
495 * @return Boolean true on success or false on failure
496 *
497 * @see http://www.php.net/manual/en/intldateformatter.setlenient.php
498 *
499 * @throws MethodArgumentValueNotImplementedException When $lenient is true
500 */
501 public function setLenient($lenient)
502 {
503 if ($lenient) {
504 throw new MethodArgumentValueNotImplementedException(__METHOD__, 'lenient', $lenient, 'Only the strict parser is supported');
505 }
506
507 return true;
508 }
509
510 /**
511 * Set the formatter's pattern
512 *
513 * @param string $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation
514 *
515 * @return Boolean true on success or false on failure
516 *
517 * @see http://www.php.net/manual/en/intldateformatter.setpattern.php
518 * @see http://userguide.icu-project.org/formatparse/datetime
519 */
520 public function setPattern($pattern)
521 {
522 if (null === $pattern) {
523 $pattern = $this->getDefaultPattern();
524 }
525
526 $this->pattern = $pattern;
527
528 return true;
529 }
530
531 /**
532 * Set the formatter's timezone identifier
533 *
534 * @param string $timeZoneId The time zone ID string of the time zone to use.
535 * If NULL or the empty string, the default time zone for the
536 * runtime is used.
537 *
538 * @return Boolean true on success or false on failure
539 *
540 * @see http://www.php.net/manual/en/intldateformatter.settimezoneid.php
541 */
542 public function setTimeZoneId($timeZoneId)
543 {
544 if (null === $timeZoneId) {
545 // In PHP 5.5 if $timeZoneId is null it fallbacks to `date_default_timezone_get()` method
546 if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) {
547 $timeZoneId = date_default_timezone_get();
548 } else {
549 // TODO: changes were made to ext/intl in PHP 5.4.4 release that need to be investigated since it will
550 // use ini's date.timezone when the time zone is not provided. As a not well tested workaround, uses UTC.
551 // See the first two items of the commit message for more information:
552 // https://github.com/php/php-src/commit/eb346ef0f419b90739aadfb6cc7b7436c5b521d9
553 $timeZoneId = getenv('TZ') ?: 'UTC';
554 }
555
556 $this->unitializedTimeZoneId = true;
557 }
558
559 // Backup original passed time zone
560 $timeZone = $timeZoneId;
561
562 // Get an Etc/GMT time zone that is accepted for \DateTimeZone
563 if ('GMT' !== $timeZoneId && 0 === strpos($timeZoneId, 'GMT')) {
564 try {
565 $timeZoneId = DateFormat\TimeZoneTransformer::getEtcTimeZoneId($timeZoneId);
566 } catch (\InvalidArgumentException $e) {
567 // Does nothing, will fallback to UTC
568 }
569 }
570
571 try {
572 $this->dateTimeZone = new \DateTimeZone($timeZoneId);
573 } catch (\Exception $e) {
574 $this->dateTimeZone = new \DateTimeZone('UTC');
575 }
576
577 $this->timeZoneId = $timeZone;
578
579 return true;
580 }
581
582 /**
583 * This method was added in PHP 5.5 as replacement for `setTimeZoneId()`
584 *
585 * @param mixed $timeZone
586 *
587 * @return Boolean true on success or false on failure
588 *
589 * @see http://www.php.net/manual/en/intldateformatter.settimezone.php
590 */
591 public function setTimeZone($timeZone)
592 {
593 return $this->setTimeZoneId($timeZone);
594 }
595
596 /**
597 * Create and returns a DateTime object with the specified timestamp and with the
598 * current time zone
599 *
600 * @param int $timestamp
601 *
602 * @return \DateTime
603 */
604 protected function createDateTime($timestamp)
605 {
606 $dateTime = new \DateTime();
607 $dateTime->setTimestamp($timestamp);
608 $dateTime->setTimezone($this->dateTimeZone);
609
610 return $dateTime;
611 }
612
613 /**
614 * Returns a pattern string based in the datetype and timetype values
615 *
616 * @return string
617 */
618 protected function getDefaultPattern()
619 {
620 $patternParts = array();
621 if (self::NONE !== $this->datetype) {
622 $patternParts[] = $this->defaultDateFormats[$this->datetype];
623 }
624 if (self::NONE !== $this->timetype) {
625 $patternParts[] = $this->defaultTimeFormats[$this->timetype];
626 }
627 $pattern = implode(' ', $patternParts);
628
629 return $pattern;
630 }
631}