GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 533da6...33cff4 )
by Robert
08:57
created

BaseFormatConverter::convertDatePhpToJui()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 0
cts 3
cp 0
rs 9.3333
c 0
b 0
f 0
cc 1
eloc 39
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace yii\helpers;
9
10
use IntlDateFormatter;
11
use Yii;
12
13
/**
14
 * BaseFormatConverter provides concrete implementation for [[FormatConverter]].
15
 *
16
 * Do not use BaseFormatConverter. Use [[FormatConverter]] instead.
17
 *
18
 * @author Carsten Brandt <[email protected]>
19
 * @author Enrica Ruedin <[email protected]>
20
 * @since 2.0
21
 */
22
class BaseFormatConverter
23
{
24
    /**
25
     * @var array the php fallback definition to use for the ICU short patterns `short`, `medium`, `long` and `full`.
26
     * This is used as fallback when the intl extension is not installed.
27
     */
28
    public static $phpFallbackDatePatterns = [
29
        'short' => [
30
            'date' => 'n/j/y',
31
            'time' => 'H:i',
32
            'datetime' => 'n/j/y H:i',
33
        ],
34
        'medium' => [
35
            'date' => 'M j, Y',
36
            'time' => 'g:i:s A',
37
            'datetime' => 'M j, Y g:i:s A',
38
        ],
39
        'long' => [
40
            'date' => 'F j, Y',
41
            'time' => 'g:i:sA',
42
            'datetime' => 'F j, Y g:i:sA',
43
        ],
44
        'full' => [
45
            'date' => 'l, F j, Y',
46
            'time' => 'g:i:sA T',
47
            'datetime' => 'l, F j, Y g:i:sA T',
48
        ],
49
    ];
50
    /**
51
     * @var array the jQuery UI fallback definition to use for the ICU short patterns `short`, `medium`, `long` and `full`.
52
     * This is used as fallback when the intl extension is not installed.
53
     */
54
    public static $juiFallbackDatePatterns = [
55
        'short' => [
56
            'date' => 'd/m/y',
57
            'time' => '',
58
            'datetime' => 'd/m/y',
59
        ],
60
        'medium' => [
61
            'date' => 'M d, yy',
62
            'time' => '',
63
            'datetime' => 'M d, yy',
64
        ],
65
        'long' => [
66
            'date' => 'MM d, yy',
67
            'time' => '',
68
            'datetime' => 'MM d, yy',
69
        ],
70
        'full' => [
71
            'date' => 'DD, MM d, yy',
72
            'time' => '',
73
            'datetime' => 'DD, MM d, yy',
74
        ],
75
    ];
76
77
    private static $_icuShortFormats = [
78
        'short'  => 3, // IntlDateFormatter::SHORT,
79
        'medium' => 2, // IntlDateFormatter::MEDIUM,
80
        'long'   => 1, // IntlDateFormatter::LONG,
81
        'full'   => 0, // IntlDateFormatter::FULL,
82
    ];
83
84
85
    /**
86
     * Converts a date format pattern from [ICU format][] to [php date() function format][].
87
     *
88
     * The conversion is limited to date patterns that do not use escaped characters.
89
     * Patterns like `d 'of' MMMM yyyy` which will result in a date like `1 of December 2014` may not be converted correctly
90
     * because of the use of escaped characters.
91
     *
92
     * Pattern constructs that are not supported by the PHP format will be removed.
93
     *
94
     * [php date() function format]: http://php.net/manual/en/function.date.php
95
     * [ICU format]: http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax
96
     *
97
     * @param string $pattern date format pattern in ICU format.
98
     * @param string $type 'date', 'time', or 'datetime'.
99
     * @param string $locale the locale to use for converting ICU short patterns `short`, `medium`, `long` and `full`.
100
     * If not given, `Yii::$app->language` will be used.
101
     * @return string The converted date format pattern.
102
     */
103 180
    public static function convertDateIcuToPhp($pattern, $type = 'date', $locale = null)
104
    {
105 180
        if (isset(self::$_icuShortFormats[$pattern])) {
106 6
            if (extension_loaded('intl')) {
107 1
                if ($locale === null) {
108
                    $locale = Yii::$app->language;
109
                }
110 1
                if ($type === 'date') {
111 1
                    $formatter = new IntlDateFormatter($locale, self::$_icuShortFormats[$pattern], IntlDateFormatter::NONE);
112
                } elseif ($type === 'time') {
113
                    $formatter = new IntlDateFormatter($locale, IntlDateFormatter::NONE, self::$_icuShortFormats[$pattern]);
114
                } else {
115
                    $formatter = new IntlDateFormatter($locale, self::$_icuShortFormats[$pattern], self::$_icuShortFormats[$pattern]);
116
                }
117 1
                $pattern = $formatter->getPattern();
118
            } else {
119 5
                return static::$phpFallbackDatePatterns[$pattern][$type];
120
            }
121
        }
122
        // http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax
123
        // escaped text
124 176
        $escaped = [];
125 176
        if (preg_match_all('/(?<!\')\'(.*?[^\'])\'(?!\')/', $pattern, $matches, PREG_SET_ORDER)) {
126 3
            foreach ($matches as $match) {
127 3
                $match[1] = str_replace('\'\'', '\'', $match[1]);
128 3
                $escaped[$match[0]] = '\\'.implode('\\', preg_split('//u', $match[1], -1, PREG_SPLIT_NO_EMPTY));
129
            }
130
        }
131 176
        return strtr($pattern, array_merge($escaped, [
132 176
            '\'\'' => '\\\'', // two single quotes produce one
133
            'G' => '', // era designator like (Anno Domini)
134
            'Y' => 'o',     // 4digit year of "Week of Year"
135
            'y' => 'Y',     // 4digit year e.g. 2014
136
            'yyyy' => 'Y',  // 4digit year e.g. 2014
137
            'yy' => 'y',    // 2digit year number eg. 14
138
            'u' => '',      // extended year e.g. 4601
139
            'U' => '',      // cyclic year name, as in Chinese lunar calendar
140
            'r' => '',        // related Gregorian year e.g. 1996
141
            'Q' => '',      // number of quarter
142
            'QQ' => '',     // number of quarter '02'
143
            'QQQ' => '',    // quarter 'Q2'
144
            'QQQQ' => '',   // quarter '2nd quarter'
145
            'QQQQQ' => '',  // number of quarter '2'
146
            'q' => '',      // number of Stand Alone quarter
147
            'qq' => '',     // number of Stand Alone quarter '02'
148
            'qqq' => '',    // Stand Alone quarter 'Q2'
149
            'qqqq' => '',   // Stand Alone quarter '2nd quarter'
150
            'qqqqq' => '',  // number of Stand Alone quarter '2'
151
            'M' => 'n',     // Numeric representation of a month, without leading zeros
152
            'MM' => 'm',    // Numeric representation of a month, with leading zeros
153
            'MMM' => 'M',   // A short textual representation of a month, three letters
154
            'MMMM' => 'F',  // A full textual representation of a month, such as January or March
155
            'MMMMM' => '',  //
156
            'L' => 'n',     // Stand alone month in year
157
            'LL' => 'm',    // Stand alone month in year
158
            'LLL' => 'M',   // Stand alone month in year
159
            'LLLL' => 'F',  // Stand alone month in year
160
            'LLLLL' => '',  // Stand alone month in year
161
            'w' => 'W',     // ISO-8601 week number of year
162
            'ww' => 'W',    // ISO-8601 week number of year
163
            'W' => '',      // week of the current month
164
            'd' => 'j',     // day without leading zeros
165
            'dd' => 'd',    // day with leading zeros
166
            'D' => 'z',     // day of the year 0 to 365
167
            'F' => '',      // Day of Week in Month. eg. 2nd Wednesday in July
168
            'g' => '',      // Modified Julian day. This is different from the conventional Julian day number in two regards.
169
            'E' => 'D',     // day of week written in short form eg. Sun
170
            'EE' => 'D',
171
            'EEE' => 'D',
172
            'EEEE' => 'l',  // day of week fully written eg. Sunday
173
            'EEEEE' => '',
174
            'EEEEEE' => '',
175
            'e' => 'N',     // ISO-8601 numeric representation of the day of the week 1=Mon to 7=Sun
176
            'ee' => 'N',    // php 'w' 0=Sun to 6=Sat isn't supported by ICU -> 'w' means week number of year
177
            'eee' => 'D',
178
            'eeee' => 'l',
179
            'eeeee' => '',
180
            'eeeeee' => '',
181
            'c' => 'N',     // ISO-8601 numeric representation of the day of the week 1=Mon to 7=Sun
182
            'cc' => 'N',    // php 'w' 0=Sun to 6=Sat isn't supported by ICU -> 'w' means week number of year
183
            'ccc' => 'D',
184
            'cccc' => 'l',
185
            'ccccc' => '',
186
            'cccccc' => '',
187
            'a' => 'a',     // am/pm marker
188
            'h' => 'g',     // 12-hour format of an hour without leading zeros 1 to 12h
189
            'hh' => 'h',    // 12-hour format of an hour with leading zeros, 01 to 12 h
190
            'H' => 'G',     // 24-hour format of an hour without leading zeros 0 to 23h
191
            'HH' => 'H',    // 24-hour format of an hour with leading zeros, 00 to 23 h
192
            'k' => '',      // hour in day (1~24)
193
            'kk' => '',     // hour in day (1~24)
194
            'K' => '',      // hour in am/pm (0~11)
195
            'KK' => '',     // hour in am/pm (0~11)
196
            'm' => 'i',     // Minutes without leading zeros, not supported by php but we fallback
197
            'mm' => 'i',    // Minutes with leading zeros
198
            's' => 's',     // Seconds, without leading zeros, not supported by php but we fallback
199
            'ss' => 's',    // Seconds, with leading zeros
200
            'S' => '',      // fractional second
201
            'SS' => '',     // fractional second
202
            'SSS' => '',    // fractional second
203
            'SSSS' => '',   // fractional second
204
            'A' => '',      // milliseconds in day
205
            'z' => 'T',     // Timezone abbreviation
206
            'zz' => 'T',    // Timezone abbreviation
207
            'zzz' => 'T',   // Timezone abbreviation
208
            'zzzz' => 'T',  // Timzone full name, not supported by php but we fallback
209
            'Z' => 'O',     // Difference to Greenwich time (GMT) in hours
210
            'ZZ' => 'O',    // Difference to Greenwich time (GMT) in hours
211
            'ZZZ' => 'O',   // Difference to Greenwich time (GMT) in hours
212
            'ZZZZ' => '\G\M\TP', // Time Zone: long localized GMT (=OOOO) e.g. GMT-08:00
213
            'ZZZZZ' => '',  //  TIme Zone: ISO8601 extended hms? (=XXXXX)
214
            'O' => '',      // Time Zone: short localized GMT e.g. GMT-8
215
            'OOOO' => '\G\M\TP', //  Time Zone: long localized GMT (=ZZZZ) e.g. GMT-08:00
216
            'v' => '\G\M\TP', // Time Zone: generic non-location (falls back first to VVVV and then to OOOO) using the ICU defined fallback here
217
            'vvvv' => '\G\M\TP', // Time Zone: generic non-location (falls back first to VVVV and then to OOOO) using the ICU defined fallback here
218
            'V' => '',      // Time Zone: short time zone ID
219
            'VV' => 'e',    // Time Zone: long time zone ID
220
            'VVV' => '',    // Time Zone: time zone exemplar city
221
            'VVVV' => '\G\M\TP', // Time Zone: generic location (falls back to OOOO) using the ICU defined fallback here
222
            'X' => '',      // Time Zone: ISO8601 basic hm?, with Z for 0, e.g. -08, +0530, Z
223
            'XX' => 'O, \Z', // Time Zone: ISO8601 basic hm, with Z, e.g. -0800, Z
224
            'XXX' => 'P, \Z',    // Time Zone: ISO8601 extended hm, with Z, e.g. -08:00, Z
225
            'XXXX' => '',   // Time Zone: ISO8601 basic hms?, with Z, e.g. -0800, -075258, Z
226
            'XXXXX' => '',  // Time Zone: ISO8601 extended hms?, with Z, e.g. -08:00, -07:52:58, Z
227
            'x' => '',      // Time Zone: ISO8601 basic hm?, without Z for 0, e.g. -08, +0530
228
            'xx' => 'O',     // Time Zone: ISO8601 basic hm, without Z, e.g. -0800
229
            'xxx' => 'P',    // Time Zone: ISO8601 extended hm, without Z, e.g. -08:00
230
            'xxxx' => '',   // Time Zone: ISO8601 basic hms?, without Z, e.g. -0800, -075258
231
            'xxxxx' => '',  // Time Zone: ISO8601 extended hms?, without Z, e.g. -08:00, -07:52:58
232
        ]));
233
    }
234
235
    /**
236
     * Converts a date format pattern from [php date() function format][] to [ICU format][].
237
     *
238
     * The conversion is limited to date patterns that do not use escaped characters.
239
     * Patterns like `jS \o\f F Y` which will result in a date like `1st of December 2014` may not be converted correctly
240
     * because of the use of escaped characters.
241
     *
242
     * Pattern constructs that are not supported by the ICU format will be removed.
243
     *
244
     * [php date() function format]: http://php.net/manual/en/function.date.php
245
     * [ICU format]: http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax
246
     *
247
     * @param string $pattern date format pattern in php date()-function format.
248
     * @return string The converted date format pattern.
249
     */
250 5
    public static function convertDatePhpToIcu($pattern)
251
    {
252
        // http://php.net/manual/en/function.date.php
253 5
        return strtr($pattern, [
254
            // Day
255 5
            'd' => 'dd',    // Day of the month, 2 digits with leading zeros 	01 to 31
256
            'D' => 'eee',   // A textual representation of a day, three letters 	Mon through Sun
257
            'j' => 'd',     // Day of the month without leading zeros 	1 to 31
258
            'l' => 'eeee',  // A full textual representation of the day of the week 	Sunday through Saturday
259
            'N' => 'e',     // ISO-8601 numeric representation of the day of the week, 1 (for Monday) through 7 (for Sunday)
260
            'S' => '',      // English ordinal suffix for the day of the month, 2 characters 	st, nd, rd or th. Works well with j
261
            'w' => '',      // Numeric representation of the day of the week 	0 (for Sunday) through 6 (for Saturday)
262
            'z' => 'D',     // The day of the year (starting from 0) 	0 through 365
263
            // Week
264
            'W' => 'w',     // ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) 	Example: 42 (the 42nd week in the year)
265
            // Month
266
            'F' => 'MMMM',  // A full textual representation of a month, January through December
267
            'm' => 'MM',    // Numeric representation of a month, with leading zeros 	01 through 12
268
            'M' => 'MMM',   // A short textual representation of a month, three letters 	Jan through Dec
269
            'n' => 'M',     // Numeric representation of a month, without leading zeros 	1 through 12, not supported by ICU but we fallback to "with leading zero"
270
            't' => '',      // Number of days in the given month 	28 through 31
271
            // Year
272
            'L' => '',      // Whether it's a leap year, 1 if it is a leap year, 0 otherwise.
273
            'o' => 'Y',     // ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.
274
            'Y' => 'yyyy',  // A full numeric representation of a year, 4 digits 	Examples: 1999 or 2003
275
            'y' => 'yy',    // A two digit representation of a year 	Examples: 99 or 03
276
            // Time
277
            'a' => 'a',     // Lowercase Ante meridiem and Post meridiem, am or pm
278
            'A' => 'a',     // Uppercase Ante meridiem and Post meridiem, AM or PM, not supported by ICU but we fallback to lowercase
279
            'B' => '',      // Swatch Internet time 	000 through 999
280
            'g' => 'h',     // 12-hour format of an hour without leading zeros 	1 through 12
281
            'G' => 'H',     // 24-hour format of an hour without leading zeros 0 to 23h
282
            'h' => 'hh',    // 12-hour format of an hour with leading zeros, 01 to 12 h
283
            'H' => 'HH',    // 24-hour format of an hour with leading zeros, 00 to 23 h
284
            'i' => 'mm',    // Minutes with leading zeros 	00 to 59
285
            's' => 'ss',    // Seconds, with leading zeros 	00 through 59
286
            'u' => '',      // Microseconds. Example: 654321
287
            // Timezone
288
            'e' => 'VV',    // Timezone identifier. Examples: UTC, GMT, Atlantic/Azores
289
            'I' => '',      // Whether or not the date is in daylight saving time, 1 if Daylight Saving Time, 0 otherwise.
290
            'O' => 'xx',    // Difference to Greenwich time (GMT) in hours, Example: +0200
291
            'P' => 'xxx',   // Difference to Greenwich time (GMT) with colon between hours and minutes, Example: +02:00
292
            'T' => 'zzz',   // Timezone abbreviation, Examples: EST, MDT ...
293
            'Z' => '',    // Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 50400
294
            // Full Date/Time
295
            'c' => 'yyyy-MM-dd\'T\'HH:mm:ssxxx', // ISO 8601 date, e.g. 2004-02-12T15:19:21+00:00
296
            'r' => 'eee, dd MMM yyyy HH:mm:ss xx', // RFC 2822 formatted date, Example: Thu, 21 Dec 2000 16:01:07 +0200
297
            'U' => '',      // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
298
        ]);
299
    }
300
301
    /**
302
     * Converts a date format pattern from [ICU format][] to [jQuery UI date format][].
303
     *
304
     * Pattern constructs that are not supported by the jQuery UI format will be removed.
305
     *
306
     * [jQuery UI date format]: http://api.jqueryui.com/datepicker/#utility-formatDate
307
     * [ICU format]: http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax
308
     *
309
     * @param string $pattern date format pattern in ICU format.
310
     * @param string $type 'date', 'time', or 'datetime'.
311
     * @param string $locale the locale to use for converting ICU short patterns `short`, `medium`, `long` and `full`.
312
     * If not given, `Yii::$app->language` will be used.
313
     * @return string The converted date format pattern.
314
     */
315 2
    public static function convertDateIcuToJui($pattern, $type = 'date', $locale = null)
316
    {
317 2
        if (isset(self::$_icuShortFormats[$pattern])) {
318
            if (extension_loaded('intl')) {
319
                if ($locale === null) {
320
                    $locale = Yii::$app->language;
321
                }
322
                if ($type === 'date') {
323
                    $formatter = new IntlDateFormatter($locale, self::$_icuShortFormats[$pattern], IntlDateFormatter::NONE);
324
                } elseif ($type === 'time') {
325
                    $formatter = new IntlDateFormatter($locale, IntlDateFormatter::NONE, self::$_icuShortFormats[$pattern]);
326
                } else {
327
                    $formatter = new IntlDateFormatter($locale, self::$_icuShortFormats[$pattern], self::$_icuShortFormats[$pattern]);
328
                }
329
                $pattern = $formatter->getPattern();
330
            } else {
331
                return static::$juiFallbackDatePatterns[$pattern][$type];
332
            }
333
        }
334
        // http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax
335
        // escaped text
336 2
        $escaped = [];
337 2
        if (preg_match_all('/(?<!\')\'.*?[^\']\'(?!\')/', $pattern, $matches)) {
338 2
            foreach ($matches[0] as $match) {
339 2
                $escaped[$match] = $match;
340
            }
341
        }
342 2
        return strtr($pattern, array_merge($escaped, [
343 2
            'G' => '',      // era designator like (Anno Domini)
344
            'Y' => '',      // 4digit year of "Week of Year"
345
            'y' => 'yy',    // 4digit year e.g. 2014
346
            'yyyy' => 'yy', // 4digit year e.g. 2014
347
            'yy' => 'y',    // 2digit year number eg. 14
348
            'u' => '',      // extended year e.g. 4601
349
            'U' => '',      // cyclic year name, as in Chinese lunar calendar
350
            'r' => '',      // related Gregorian year e.g. 1996
351
            'Q' => '',      // number of quarter
352
            'QQ' => '',     // number of quarter '02'
353
            'QQQ' => '',    // quarter 'Q2'
354
            'QQQQ' => '',   // quarter '2nd quarter'
355
            'QQQQQ' => '',  // number of quarter '2'
356
            'q' => '',      // number of Stand Alone quarter
357
            'qq' => '',     // number of Stand Alone quarter '02'
358
            'qqq' => '',    // Stand Alone quarter 'Q2'
359
            'qqqq' => '',   // Stand Alone quarter '2nd quarter'
360
            'qqqqq' => '',  // number of Stand Alone quarter '2'
361
            'M' => 'm',    // Numeric representation of a month, without leading zeros
362
            'MM' => 'mm',   // Numeric representation of a month, with leading zeros
363
            'MMM' => 'M',   // A short textual representation of a month, three letters
364
            'MMMM' => 'MM', // A full textual representation of a month, such as January or March
365
            'MMMMM' => '',  //
366
            'L' => 'm',     // Stand alone month in year
367
            'LL' => 'mm',   // Stand alone month in year
368
            'LLL' => 'M',   // Stand alone month in year
369
            'LLLL' => 'MM', // Stand alone month in year
370
            'LLLLL' => '',  // Stand alone month in year
371
            'w' => '',      // ISO-8601 week number of year
372
            'ww' => '',     // ISO-8601 week number of year
373
            'W' => '',      // week of the current month
374
            'd' => 'd',     // day without leading zeros
375
            'dd' => 'dd',   // day with leading zeros
376
            'D' => 'o',     // day of the year 0 to 365
377
            'F' => '',      // Day of Week in Month. eg. 2nd Wednesday in July
378
            'g' => '',      // Modified Julian day. This is different from the conventional Julian day number in two regards.
379
            'E' => 'D',     // day of week written in short form eg. Sun
380
            'EE' => 'D',
381
            'EEE' => 'D',
382
            'EEEE' => 'DD', // day of week fully written eg. Sunday
383
            'EEEEE' => '',
384
            'EEEEEE' => '',
385
            'e' => '',      // ISO-8601 numeric representation of the day of the week 1=Mon to 7=Sun
386
            'ee' => '',     // php 'w' 0=Sun to 6=Sat isn't supported by ICU -> 'w' means week number of year
387
            'eee' => 'D',
388
            'eeee' => '',
389
            'eeeee' => '',
390
            'eeeeee' => '',
391
            'c' => '',      // ISO-8601 numeric representation of the day of the week 1=Mon to 7=Sun
392
            'cc' => '',     // php 'w' 0=Sun to 6=Sat isn't supported by ICU -> 'w' means week number of year
393
            'ccc' => 'D',
394
            'cccc' => 'DD',
395
            'ccccc' => '',
396
            'cccccc' => '',
397
            'a' => '',      // am/pm marker
398
            'h' => '',      // 12-hour format of an hour without leading zeros 1 to 12h
399
            'hh' => '',     // 12-hour format of an hour with leading zeros, 01 to 12 h
400
            'H' => '',      // 24-hour format of an hour without leading zeros 0 to 23h
401
            'HH' => '',     // 24-hour format of an hour with leading zeros, 00 to 23 h
402
            'k' => '',      // hour in day (1~24)
403
            'kk' => '',     // hour in day (1~24)
404
            'K' => '',      // hour in am/pm (0~11)
405
            'KK' => '',     // hour in am/pm (0~11)
406
            'm' => '',      // Minutes without leading zeros, not supported by php but we fallback
407
            'mm' => '',     // Minutes with leading zeros
408
            's' => '',      // Seconds, without leading zeros, not supported by php but we fallback
409
            'ss' => '',     // Seconds, with leading zeros
410
            'S' => '',      // fractional second
411
            'SS' => '',     // fractional second
412
            'SSS' => '',    // fractional second
413
            'SSSS' => '',   // fractional second
414
            'A' => '',      // milliseconds in day
415
            'z' => '',      // Timezone abbreviation
416
            'zz' => '',     // Timezone abbreviation
417
            'zzz' => '',    // Timezone abbreviation
418
            'zzzz' => '',   // Timzone full name, not supported by php but we fallback
419
            'Z' => '',      // Difference to Greenwich time (GMT) in hours
420
            'ZZ' => '',     // Difference to Greenwich time (GMT) in hours
421
            'ZZZ' => '',    // Difference to Greenwich time (GMT) in hours
422
            'ZZZZ' => '',   // Time Zone: long localized GMT (=OOOO) e.g. GMT-08:00
423
            'ZZZZZ' => '',  //  TIme Zone: ISO8601 extended hms? (=XXXXX)
424
            'O' => '',      // Time Zone: short localized GMT e.g. GMT-8
425
            'OOOO' => '',   //  Time Zone: long localized GMT (=ZZZZ) e.g. GMT-08:00
426
            'v' => '',      // Time Zone: generic non-location (falls back first to VVVV and then to OOOO) using the ICU defined fallback here
427
            'vvvv' => '',   // Time Zone: generic non-location (falls back first to VVVV and then to OOOO) using the ICU defined fallback here
428
            'V' => '',      // Time Zone: short time zone ID
429
            'VV' => '',     // Time Zone: long time zone ID
430
            'VVV' => '',    // Time Zone: time zone exemplar city
431
            'VVVV' => '',   // Time Zone: generic location (falls back to OOOO) using the ICU defined fallback here
432
            'X' => '',      // Time Zone: ISO8601 basic hm?, with Z for 0, e.g. -08, +0530, Z
433
            'XX' => '',     // Time Zone: ISO8601 basic hm, with Z, e.g. -0800, Z
434
            'XXX' => '',    // Time Zone: ISO8601 extended hm, with Z, e.g. -08:00, Z
435
            'XXXX' => '',   // Time Zone: ISO8601 basic hms?, with Z, e.g. -0800, -075258, Z
436
            'XXXXX' => '',  // Time Zone: ISO8601 extended hms?, with Z, e.g. -08:00, -07:52:58, Z
437
            'x' => '',      // Time Zone: ISO8601 basic hm?, without Z for 0, e.g. -08, +0530
438
            'xx' => '',     // Time Zone: ISO8601 basic hm, without Z, e.g. -0800
439
            'xxx' => '',    // Time Zone: ISO8601 extended hm, without Z, e.g. -08:00
440
            'xxxx' => '',   // Time Zone: ISO8601 basic hms?, without Z, e.g. -0800, -075258
441
            'xxxxx' => '',  // Time Zone: ISO8601 extended hms?, without Z, e.g. -08:00, -07:52:58
442
        ]));
443
    }
444
445
    /**
446
     * Converts a date format pattern from [php date() function format][] to [jQuery UI date format][].
447
     *
448
     * The conversion is limited to date patterns that do not use escaped characters.
449
     * Patterns like `jS \o\f F Y` which will result in a date like `1st of December 2014` may not be converted correctly
450
     * because of the use of escaped characters.
451
     *
452
     * Pattern constructs that are not supported by the jQuery UI format will be removed.
453
     *
454
     * [php date() function format]: http://php.net/manual/en/function.date.php
455
     * [jQuery UI date format]: http://api.jqueryui.com/datepicker/#utility-formatDate
456
     *
457
     * @param string $pattern date format pattern in php date()-function format.
458
     * @return string The converted date format pattern.
459
     */
460
    public static function convertDatePhpToJui($pattern)
461
    {
462
        // http://php.net/manual/en/function.date.php
463
        return strtr($pattern, [
464
            // Day
465
            'd' => 'dd',    // Day of the month, 2 digits with leading zeros 	01 to 31
466
            'D' => 'D',     // A textual representation of a day, three letters 	Mon through Sun
467
            'j' => 'd',     // Day of the month without leading zeros 	1 to 31
468
            'l' => 'DD',    // A full textual representation of the day of the week 	Sunday through Saturday
469
            'N' => '',      // ISO-8601 numeric representation of the day of the week, 1 (for Monday) through 7 (for Sunday)
470
            'S' => '',      // English ordinal suffix for the day of the month, 2 characters 	st, nd, rd or th. Works well with j
471
            'w' => '',      // Numeric representation of the day of the week 	0 (for Sunday) through 6 (for Saturday)
472
            'z' => 'o',     // The day of the year (starting from 0) 	0 through 365
473
            // Week
474
            'W' => '',      // ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) 	Example: 42 (the 42nd week in the year)
475
            // Month
476
            'F' => 'MM',    // A full textual representation of a month, January through December
477
            'm' => 'mm',    // Numeric representation of a month, with leading zeros 	01 through 12
478
            'M' => 'M',     // A short textual representation of a month, three letters 	Jan through Dec
479
            'n' => 'm',     // Numeric representation of a month, without leading zeros 	1 through 12
480
            't' => '',      // Number of days in the given month 	28 through 31
481
            // Year
482
            'L' => '',      // Whether it's a leap year, 1 if it is a leap year, 0 otherwise.
483
            'o' => '',      // ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.
484
            'Y' => 'yy',    // A full numeric representation of a year, 4 digits 	Examples: 1999 or 2003
485
            'y' => 'y',     // A two digit representation of a year 	Examples: 99 or 03
486
            // Time
487
            'a' => '',      // Lowercase Ante meridiem and Post meridiem, am or pm
488
            'A' => '',      // Uppercase Ante meridiem and Post meridiem, AM or PM, not supported by ICU but we fallback to lowercase
489
            'B' => '',      // Swatch Internet time 	000 through 999
490
            'g' => '',      // 12-hour format of an hour without leading zeros 	1 through 12
491
            'G' => '',      // 24-hour format of an hour without leading zeros 0 to 23h
492
            'h' => '',      // 12-hour format of an hour with leading zeros, 01 to 12 h
493
            'H' => '',      // 24-hour format of an hour with leading zeros, 00 to 23 h
494
            'i' => '',      // Minutes with leading zeros 	00 to 59
495
            's' => '',      // Seconds, with leading zeros 	00 through 59
496
            'u' => '',      // Microseconds. Example: 654321
497
            // Timezone
498
            'e' => '',      // Timezone identifier. Examples: UTC, GMT, Atlantic/Azores
499
            'I' => '',      // Whether or not the date is in daylight saving time, 1 if Daylight Saving Time, 0 otherwise.
500
            'O' => '',      // Difference to Greenwich time (GMT) in hours, Example: +0200
501
            'P' => '',      // Difference to Greenwich time (GMT) with colon between hours and minutes, Example: +02:00
502
            'T' => '',      // Timezone abbreviation, Examples: EST, MDT ...
503
            'Z' => '',      // Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 50400
504
            // Full Date/Time
505
            'c' => 'yyyy-MM-dd', // ISO 8601 date, e.g. 2004-02-12T15:19:21+00:00, skipping the time here because it is not supported
506
            'r' => 'D, d M yy', // RFC 2822 formatted date, Example: Thu, 21 Dec 2000 16:01:07 +0200, skipping the time here because it is not supported
507
            'U' => '@',     // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
508
        ]);
509
    }
510
}
511