19
19
use Symfony \Component \Intl \Locale \StubLocale ;
20
20
21
21
/**
22
- * Provides a stub IntlDateFormatter for the 'en' locale.
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}
23
43
*
24
44
* @author Igor Wiedler <igor@wiedler.ch>
45
+ * @author Bernhard Schussek <bschussek@gmail.com>
25
46
*/
26
47
class StubIntlDateFormatter
27
48
{
@@ -108,24 +129,24 @@ class StubIntlDateFormatter
108
129
/**
109
130
* Constructor
110
131
*
111
- * @param string $locale The locale code
132
+ * @param string $locale The locale code. The only currently supported locale is "en".
112
133
* @param int $datetype Type of date formatting, one of the format type constants
113
134
* @param int $timetype Type of time formatting, one of the format type constants
114
135
* @param string $timezone Timezone identifier
115
- * @param int $calendar Calendar to use for formatting or parsing; default is Gregorian.
116
- * One of the calendar constants .
136
+ * @param int $calendar Calendar to use for formatting or parsing. The only currently
137
+ *supported value is IntlDateFormatter::GREGORIAN .
117
138
* @param string $pattern Optional pattern to use when formatting
118
139
*
119
140
* @see http://www.php.net/manual/en/intldateformatter.create.php
120
141
* @see http://userguide.icu-project.org/formatparse/datetime
121
142
*
122
- * @throws MethodArgumentValueNotImplementedException When $locale different than'en' is passed
143
+ * @throws MethodArgumentValueNotImplementedException When $locale different than"en" is passed
123
144
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
124
145
*/
125
146
public function __construct ($ locale ,$ datetype ,$ timetype ,$ timezone =null ,$ calendar =self ::GREGORIAN ,$ pattern =null )
126
147
{
127
148
if ('en ' !==$ locale ) {
128
- throw new MethodArgumentValueNotImplementedException (__METHOD__ ,'locale ' ,$ locale ,'Only the \' en \' locale is supported ' );
149
+ throw new MethodArgumentValueNotImplementedException (__METHOD__ ,'locale ' ,$ locale ,'Only the locale "en" is supported ' );
129
150
}
130
151
131
152
if (self ::GREGORIAN !==$ calendar ) {
@@ -142,7 +163,7 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
142
163
/**
143
164
* Static constructor
144
165
*
145
- * @param string $locale The locale code
166
+ * @param string $locale The locale code. The only currently supported locale is "en".
146
167
* @param int $datetype Type of date formatting, one of the format type constants
147
168
* @param int $timetype Type of time formatting, one of the format type constants
148
169
* @param string $timezone Timezone identifier
@@ -155,7 +176,8 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
155
176
* @see http://www.php.net/manual/en/intldateformatter.create.php
156
177
* @see http://userguide.icu-project.org/formatparse/datetime
157
178
*
158
- * @throws MethodArgumentValueNotImplementedException When $locale different than 'en' is passed
179
+ * @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
180
+ * @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
159
181
*/
160
182
public static function create ($ locale ,$ datetype ,$ timetype ,$ timezone =null ,$ calendar =self ::GREGORIAN ,$ pattern =null )
161
183
{
@@ -165,9 +187,10 @@ public static function create($locale, $datetype, $timetype, $timezone = null, $
165
187
/**
166
188
* Format the date/time value (timestamp) as a string
167
189
*
168
- * @param mixed $timestamp Unix timestamp to format
190
+ * @param integer|\DateTime $timestamp The timestamp to format. \DateTime objects
191
+ * are supported as of PHP 5.3.4.
169
192
*
170
- * @return string The formatted value
193
+ * @return string|Boolean The formatted value or false if formatting failed.
171
194
*
172
195
* @see http://www.php.net/manual/en/intldateformatter.format.php
173
196
*
@@ -220,7 +243,7 @@ public function format($timestamp)
220
243
}
221
244
222
245
/**
223
- * Formats an object
246
+ *Not supported. Formats an object
224
247
*
225
248
* @param object $object
226
249
* @param mixed $format
@@ -240,7 +263,8 @@ public function formatObject($object, $format = null, $locale = null)
240
263
/**
241
264
* Returns the formatter's calendar
242
265
*
243
- * @return int The calendar being used by the formatter
266
+ * @return int The calendar being used by the formatter. Currently always returns
267
+ * IntlDateFormatter::GREGORIAN.
244
268
*
245
269
* @see http://www.php.net/manual/en/intldateformatter.getcalendar.php
246
270
*/
@@ -250,7 +274,7 @@ public function getCalendar()
250
274
}
251
275
252
276
/**
253
- * Returns the formatter's calendar object
277
+ *Not supported. Returns the formatter's calendar object
254
278
*
255
279
* @return object The calendar's object being used by the formatter
256
280
*
@@ -302,9 +326,10 @@ public function getErrorMessage()
302
326
/**
303
327
* Returns the formatter's locale
304
328
*
305
- * @param int $type The locale name type to returnbetween valid or actual (StubLocale ::VALID_LOCALE orStubLocale ::ACTUAL_LOCALE, respectively )
329
+ * @param int $typeNot supported. The locale name type to return(Locale ::VALID_LOCALE orLocale ::ACTUAL_LOCALE)
306
330
*
307
- * @return string The locale name used to create the formatter
331
+ * @return string The locale used to create the formatter. Currently always
332
+ * returns "en".
308
333
*
309
334
* @see http://www.php.net/manual/en/intldateformatter.getlocale.php
310
335
*/
@@ -359,7 +384,7 @@ public function getTimeZoneId()
359
384
}
360
385
361
386
/**
362
- * Returns the formatter's timezone
387
+ *Not supported. Returns the formatter's timezone
363
388
*
364
389
* @return mixed The timezone used by the formatter
365
390
*
@@ -375,7 +400,7 @@ public function getTimeZone()
375
400
/**
376
401
* Returns whether the formatter is lenient
377
402
*
378
- * @return Boolean
403
+ * @return Boolean Currently always returns false.
379
404
*
380
405
* @see http://www.php.net/manual/en/intldateformatter.islenient.php
381
406
*
@@ -387,7 +412,7 @@ public function isLenient()
387
412
}
388
413
389
414
/**
390
- * Parse string to a field-based time value
415
+ *Not supported. Parse string to a field-based time value
391
416
*
392
417
* @param string $value String to convert to a time value
393
418
* @param int $position Position at which to start the parsing in $value (zero-based).
@@ -410,16 +435,16 @@ public function localtime($value, &$position = 0)
410
435
* Parse string to a timestamp value
411
436
*
412
437
* @param string $value String to convert to a time value
413
- * @param int $position Position at which to start the parsing in $value (zero-based).
414
- * If no error occurs before $value is consumed, $parse_pos will
415
- * contain -1 otherwise it will contain the position at which parsing
416
- * ended. If $parse_pos > strlen($value), the parse fails immediately.
438
+ * @param int $positionNot 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.
417
442
*
418
443
* @return string Parsed value as a timestamp
419
444
*
420
445
* @see http://www.php.net/manual/en/intldateformatter.parse.php
421
446
*
422
- * @throws MethodArgumentNotImplementedException When $position different than null, behavior not implemented
447
+ * @throws MethodArgumentNotImplementedException When $position different than null, behavior not implemented
423
448
*/
424
449
public function parse ($ value , &$ position =null )
425
450
{
@@ -441,7 +466,7 @@ public function parse($value, &$position = null)
441
466
}
442
467
443
468
/**
444
- * Set the formatter's calendar
469
+ *Not supported. Set the formatter's calendar
445
470
*
446
471
* @param string $calendar The calendar to use. Default is IntlDateFormatter::GREGORIAN.
447
472
*
@@ -464,7 +489,8 @@ public function setCalendar($calendar)
464
489
* patterns, parsing as much as possible to obtain a value. Extra space, unrecognized tokens, or
465
490
* invalid values ("February 30th") are not accepted.
466
491
*
467
- * @param Boolean $lenient Sets whether the parser is lenient or not, default is false (strict)
492
+ * @param Boolean $lenient Sets whether the parser is lenient or not. Currently
493
+ * only false (strict) is supported.
468
494
*
469
495
* @return Boolean true on success or false on failure
470
496
*
@@ -477,6 +503,8 @@ public function setLenient($lenient)
477
503
if ($ lenient ) {
478
504
throw new MethodArgumentValueNotImplementedException (__METHOD__ ,'lenient ' ,$ lenient ,'Only the strict parser is supported ' );
479
505
}
506
+
507
+ return true ;
480
508
}
481
509
482
510
/**
@@ -496,6 +524,8 @@ public function setPattern($pattern)
496
524
}
497
525
498
526
$ this ->pattern =$ pattern ;
527
+
528
+ return true ;
499
529
}
500
530
501
531
/**