Skip to content

Commit cdd5aa2

Browse files
authored
Fix dateformat_format_variant3 test and split into different files (php#20901)
1 parent d8d754f commit cdd5aa2

File tree

4 files changed

+439
-388
lines changed

4 files changed

+439
-388
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
--TEST--
2+
datefmt_format_code DateTime input
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+
$d1 = new DateTime("2010-01-01 01:02:03", new DateTimeZone("UTC"));
21+
$d2 = new DateTime("2000-12-31 03:04:05", new DateTimeZone("UTC"));
22+
$d2->setTimezone(new DateTimeZone("America/Los_Angeles"));
23+
24+
$dates = [$d1, $d2];
25+
$res_str = '';
26+
27+
foreach ($dates as $date_entry) {
28+
foreach ($datetype_arr as $datetype_entry) {
29+
$res_str .= "\n------------";
30+
$res_str .= "\nDate is: ".var_export($date_entry, true);
31+
$res_str .= "\n------------";
32+
33+
$fmt = ut_datefmt_create($locale_entry, $datetype_entry, $datetype_entry, $timezone, IntlDateFormatter::GREGORIAN);
34+
$formatted = ut_datefmt_format($fmt, $date_entry);
35+
36+
// Replace narrow no-break space (U+202F) with regular space for consistent output.
37+
// INTL doesn't seem to be very consistent about it either
38+
$formatted = str_replace("\u{202F}", ' ', $formatted);
39+
40+
if (intl_get_error_code() == U_ZERO_ERROR) {
41+
$res_str .= "\nFormatted DateTime is : $formatted";
42+
} else {
43+
$res_str .= "\nError while formatting as: '" . intl_get_error_message() . "'";
44+
}
45+
}
46+
}
47+
48+
return $res_str;
49+
}
50+
51+
include_once 'ut_common.inc';
52+
ut_run();
53+
?>
54+
--EXPECT--
55+
------------
56+
Date is: \DateTime::__set_state(array(
57+
'date' => '2010-01-01 01:02:03.000000',
58+
'timezone_type' => 3,
59+
'timezone' => 'UTC',
60+
))
61+
------------
62+
Formatted DateTime is : Thursday, December 31, 2009 at 3:02:03 PM GMT-10:00
63+
------------
64+
Date is: \DateTime::__set_state(array(
65+
'date' => '2010-01-01 01:02:03.000000',
66+
'timezone_type' => 3,
67+
'timezone' => 'UTC',
68+
))
69+
------------
70+
Formatted DateTime is : December 31, 2009 at 3:02:03 PM GMT-10
71+
------------
72+
Date is: \DateTime::__set_state(array(
73+
'date' => '2010-01-01 01:02:03.000000',
74+
'timezone_type' => 3,
75+
'timezone' => 'UTC',
76+
))
77+
------------
78+
Formatted DateTime is : Dec 31, 2009, 3:02:03 PM
79+
------------
80+
Date is: \DateTime::__set_state(array(
81+
'date' => '2010-01-01 01:02:03.000000',
82+
'timezone_type' => 3,
83+
'timezone' => 'UTC',
84+
))
85+
------------
86+
Formatted DateTime is : 12/31/09, 3:02 PM
87+
------------
88+
Date is: \DateTime::__set_state(array(
89+
'date' => '2010-01-01 01:02:03.000000',
90+
'timezone_type' => 3,
91+
'timezone' => 'UTC',
92+
))
93+
------------
94+
Formatted DateTime is : 20091231 03:02 PM
95+
------------
96+
Date is: \DateTime::__set_state(array(
97+
'date' => '2000-12-30 19:04:05.000000',
98+
'timezone_type' => 3,
99+
'timezone' => 'America/Los_Angeles',
100+
))
101+
------------
102+
Formatted DateTime is : Saturday, December 30, 2000 at 5:04:05 PM GMT-10:00
103+
------------
104+
Date is: \DateTime::__set_state(array(
105+
'date' => '2000-12-30 19:04:05.000000',
106+
'timezone_type' => 3,
107+
'timezone' => 'America/Los_Angeles',
108+
))
109+
------------
110+
Formatted DateTime is : December 30, 2000 at 5:04:05 PM GMT-10
111+
------------
112+
Date is: \DateTime::__set_state(array(
113+
'date' => '2000-12-30 19:04:05.000000',
114+
'timezone_type' => 3,
115+
'timezone' => 'America/Los_Angeles',
116+
))
117+
------------
118+
Formatted DateTime is : Dec 30, 2000, 5:04:05 PM
119+
------------
120+
Date is: \DateTime::__set_state(array(
121+
'date' => '2000-12-30 19:04:05.000000',
122+
'timezone_type' => 3,
123+
'timezone' => 'America/Los_Angeles',
124+
))
125+
------------
126+
Formatted DateTime is : 12/30/00, 5:04 PM
127+
------------
128+
Date is: \DateTime::__set_state(array(
129+
'date' => '2000-12-30 19:04:05.000000',
130+
'timezone_type' => 3,
131+
'timezone' => 'America/Los_Angeles',
132+
))
133+
------------
134+
Formatted DateTime is : 20001230 05:04 PM
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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

Comments
 (0)