|
| 1 | +--TEST-- |
| 2 | +datefmt_format_code localtime array |
| 3 | +--EXTENSIONS-- |
| 4 | +intl |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | +function ut_main() |
| 8 | +{ |
| 9 | + $timezone = 'GMT-10:00'; |
| 10 | + $locale_entry = 'en_US'; |
| 11 | + |
| 12 | + $datetype_arr = [ |
| 13 | + IntlDateFormatter::FULL, |
| 14 | + IntlDateFormatter::LONG, |
| 15 | + IntlDateFormatter::MEDIUM, |
| 16 | + IntlDateFormatter::SHORT, |
| 17 | + IntlDateFormatter::NONE, |
| 18 | + ]; |
| 19 | + |
| 20 | + $localtime_arr = [ |
| 21 | + [ |
| 22 | + 'tm_sec' => 24, |
| 23 | + 'tm_min' => 3, |
| 24 | + 'tm_hour' => 19, |
| 25 | + 'tm_mday' => 3, |
| 26 | + 'tm_mon' => 3, |
| 27 | + 'tm_year' => 105, |
| 28 | + ], |
| 29 | + [ |
| 30 | + 'tm_sec' => 21, |
| 31 | + 'tm_min' => 5, |
| 32 | + 'tm_hour' => 7, |
| 33 | + 'tm_mday' => 13, |
| 34 | + 'tm_mon' => 4, |
| 35 | + 'tm_year' => 205, |
| 36 | + ], |
| 37 | + [ |
| 38 | + 'tm_sec' => 11, |
| 39 | + 'tm_min' => 13, |
| 40 | + 'tm_hour' => 0, |
| 41 | + 'tm_mday' => 17, |
| 42 | + 'tm_mon' => 11, |
| 43 | + 'tm_year' => -5, |
| 44 | + ], |
| 45 | + ]; |
| 46 | + |
| 47 | + $res_str = ''; |
| 48 | + |
| 49 | + foreach ($localtime_arr as $localtime_entry) { |
| 50 | + $res_str .= "\n------------\n"; |
| 51 | + $res_str .= "\nInput localtime is : "; |
| 52 | + $res_str .= implode(' , ', array_map( |
| 53 | + function ($k, $v) { |
| 54 | + return "$k : '$v'"; |
| 55 | + }, |
| 56 | + array_keys($localtime_entry), |
| 57 | + $localtime_entry |
| 58 | + )); |
| 59 | + |
| 60 | + $res_str .= "\n------------\n"; |
| 61 | + |
| 62 | + foreach ($datetype_arr as $datetype_entry) { |
| 63 | + $res_str .= "\nIntlDateFormatter locale = $locale_entry, datetype = $datetype_entry, timetype = $datetype_entry"; |
| 64 | + $fmt = ut_datefmt_create($locale_entry, $datetype_entry, $datetype_entry, $timezone, IntlDateFormatter::GREGORIAN); |
| 65 | + $formatted = ut_datefmt_format($fmt, $localtime_entry); |
| 66 | + |
| 67 | + // Replace narrow no-break space (U+202F) with regular space for consistent output. |
| 68 | + // INTL doesn't seem to be very consistent about it either |
| 69 | + $formatted = str_replace("\u{202F}", ' ', $formatted); |
| 70 | + |
| 71 | + if (intl_get_error_code() == U_ZERO_ERROR) { |
| 72 | + $res_str .= "\nFormatted localtime_array is : $formatted"; |
| 73 | + } else { |
| 74 | + $res_str .= "\nError while formatting as: '" . intl_get_error_message() . "'"; |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + return $res_str; |
| 80 | +} |
| 81 | + |
| 82 | +include_once 'ut_common.inc'; |
| 83 | +ut_run(); |
| 84 | +?> |
| 85 | +--EXPECT-- |
| 86 | +------------ |
| 87 | + |
| 88 | +Input localtime is : tm_sec : '24' , tm_min : '3' , tm_hour : '19' , tm_mday : '3' , tm_mon : '3' , tm_year : '105' |
| 89 | +------------ |
| 90 | + |
| 91 | +IntlDateFormatter locale = en_US, datetype = 0, timetype = 0 |
| 92 | +Formatted localtime_array is : Sunday, April 3, 2005 at 7:03:24 PM GMT-10:00 |
| 93 | +IntlDateFormatter locale = en_US, datetype = 1, timetype = 1 |
| 94 | +Formatted localtime_array is : April 3, 2005 at 7:03:24 PM GMT-10 |
| 95 | +IntlDateFormatter locale = en_US, datetype = 2, timetype = 2 |
| 96 | +Formatted localtime_array is : Apr 3, 2005, 7:03:24 PM |
| 97 | +IntlDateFormatter locale = en_US, datetype = 3, timetype = 3 |
| 98 | +Formatted localtime_array is : 4/3/05, 7:03 PM |
| 99 | +IntlDateFormatter locale = en_US, datetype = -1, timetype = -1 |
| 100 | +Formatted localtime_array is : 20050403 07:03 PM |
| 101 | +------------ |
| 102 | + |
| 103 | +Input localtime is : tm_sec : '21' , tm_min : '5' , tm_hour : '7' , tm_mday : '13' , tm_mon : '4' , tm_year : '205' |
| 104 | +------------ |
| 105 | + |
| 106 | +IntlDateFormatter locale = en_US, datetype = 0, timetype = 0 |
| 107 | +Formatted localtime_array is : Wednesday, May 13, 2105 at 7:05:21 AM GMT-10:00 |
| 108 | +IntlDateFormatter locale = en_US, datetype = 1, timetype = 1 |
| 109 | +Formatted localtime_array is : May 13, 2105 at 7:05:21 AM GMT-10 |
| 110 | +IntlDateFormatter locale = en_US, datetype = 2, timetype = 2 |
| 111 | +Formatted localtime_array is : May 13, 2105, 7:05:21 AM |
| 112 | +IntlDateFormatter locale = en_US, datetype = 3, timetype = 3 |
| 113 | +Formatted localtime_array is : 5/13/05, 7:05 AM |
| 114 | +IntlDateFormatter locale = en_US, datetype = -1, timetype = -1 |
| 115 | +Formatted localtime_array is : 21050513 07:05 AM |
| 116 | +------------ |
| 117 | + |
| 118 | +Input localtime is : tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_mday : '17' , tm_mon : '11' , tm_year : '-5' |
| 119 | +------------ |
| 120 | + |
| 121 | +IntlDateFormatter locale = en_US, datetype = 0, timetype = 0 |
| 122 | +Formatted localtime_array is : Tuesday, December 17, 1895 at 12:13:11 AM GMT-10:00 |
| 123 | +IntlDateFormatter locale = en_US, datetype = 1, timetype = 1 |
| 124 | +Formatted localtime_array is : December 17, 1895 at 12:13:11 AM GMT-10 |
| 125 | +IntlDateFormatter locale = en_US, datetype = 2, timetype = 2 |
| 126 | +Formatted localtime_array is : Dec 17, 1895, 12:13:11 AM |
| 127 | +IntlDateFormatter locale = en_US, datetype = 3, timetype = 3 |
| 128 | +Formatted localtime_array is : 12/17/95, 12:13 AM |
| 129 | +IntlDateFormatter locale = en_US, datetype = -1, timetype = -1 |
| 130 | +Formatted localtime_array is : 18951217 12:13 AM |
0 commit comments