1--TEST--
2datefmt_format_code() and datefmt_parse_code()
3--EXTENSIONS--
4intl
5--SKIPIF--
6<?php if (version_compare(INTL_ICU_VERSION, '51.2') < 0) die('skip for ICU >= 51.2'); ?>
7<?php if (version_compare(INTL_ICU_VERSION, '72.1') >= 0) die('skip for ICU < 72.1'); ?>
8--FILE--
9<?php
10
11/*
12 * Test for the datefmt_format  function
13 */
14
15
16function ut_main()
17{
18    $timezone = 'GMT+05:00';
19
20    $locale_arr = array (
21        'en_US'
22    );
23
24    $datetype_arr = array (
25                IntlDateFormatter::FULL,
26                IntlDateFormatter::LONG,
27                IntlDateFormatter::MEDIUM
28        );
29
30        $res_str = '';
31
32
33    $time_arr = array (
34        0,
35        -1200000,
36        1200000,
37        2200000000,
38        -2200000000,
39        90099999,
40        3600,
41        -3600
42    );
43
44    $localtime_arr1 = array (
45        'tm_sec' => 24 ,
46        'tm_min' => 3,
47        'tm_hour' => 19,
48        'tm_mday' => 3,
49        'tm_mon' => 3,
50        'tm_year' => 105,
51    );
52    $localtime_arr2 = array (
53        'tm_sec' => 21,
54        'tm_min' => 5,
55        'tm_hour' => 7,
56        'tm_mday' => 13,
57        'tm_mon' => 7,
58        'tm_year' => 205,
59    );
60    $localtime_arr3 = array (
61            'tm_sec' => 11,
62            'tm_min' => 13,
63            'tm_hour' => 0,
64            'tm_mday' => 17,
65            'tm_mon' => 11,
66            'tm_year' => -5
67        );
68
69    $localtime_arr = array (
70        $localtime_arr1,
71        $localtime_arr2,
72        $localtime_arr3
73    );
74
75    //Test format and parse with a timestamp : long
76    foreach( $time_arr as $timestamp_entry){
77        $res_str .= "\n------------\n";
78        $res_str .= "\nInput timestamp is : $timestamp_entry";
79        $res_str .= "\n------------\n";
80        foreach( $locale_arr as $locale_entry ){
81            foreach( $datetype_arr as $datetype_entry ) {
82                $res_str .= "\nIntlDateFormatter locale= $locale_entry ,datetype = $datetype_entry ,timetype =$datetype_entry ";
83                $fmt = ut_datefmt_create( $locale_entry , $datetype_entry ,$datetype_entry,$timezone);
84                $formatted = ut_datefmt_format( $fmt , $timestamp_entry);
85                $res_str .= "\nFormatted timestamp is : $formatted";
86                $parsed = ut_datefmt_parse( $fmt , $formatted);
87                if( intl_get_error_code() == U_ZERO_ERROR){
88                    $res_str .= "\nParsed timestamp is : $parsed";
89                }else{
90                    $res_str .= "\nError while parsing as: '".intl_get_error_message()."'";
91                }
92            }
93        }
94    }
95
96    //Test format and parse with a localtime :array
97    foreach( $localtime_arr as $localtime_entry){
98        $res_str .= "\n------------\n";
99        $res_str .= "\nInput localtime is : ";
100        foreach( $localtime_entry as $key => $value){
101                    $res_str .= "$key : '$value' , ";
102        }
103
104        $res_str .= "\n------------\n";
105        foreach( $locale_arr as $locale_entry ){
106            foreach( $datetype_arr as $datetype_entry ) {
107                $res_str .= "\nIntlDateFormatter locale= $locale_entry ,datetype = $datetype_entry ,timetype =$datetype_entry ";
108                $fmt = ut_datefmt_create( $locale_entry , $datetype_entry ,$datetype_entry,$timezone);
109                $formatted1 = ut_datefmt_format( $fmt , $localtime_entry);
110                if( intl_get_error_code() == U_ZERO_ERROR){
111                    $res_str .= "\nFormatted localtime_array is : $formatted1";
112                }else{
113                    $res_str .= "\nError while formatting as: '".intl_get_error_message()."'";
114                }
115                //Parsing
116                $parsed_arr = ut_datefmt_localtime( $fmt, $formatted1 );
117
118                if( $parsed_arr){
119                    $res_str .= "\nParsed array is: ";
120                    foreach( $parsed_arr as $key => $value){
121                        $res_str .= "$key : '$value' , ";
122                    }
123                }
124/*
125                else{
126                    //$res_str .= "No values found from LocaleTime parsing.";
127                    $res_str .= "\tError : '".intl_get_error_message()."'";
128                }
129*/
130            }
131        }
132    }
133
134    return $res_str;
135
136}
137
138include_once( 'ut_common.inc' );
139
140// Run the test
141ut_run();
142?>
143--EXPECT--
144------------
145
146Input timestamp is : 0
147------------
148
149IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
150Formatted timestamp is : Thursday, January 1, 1970 at 5:00:00 AM GMT+05:00
151Parsed timestamp is : 0
152IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
153Formatted timestamp is : January 1, 1970 at 5:00:00 AM GMT+5
154Parsed timestamp is : 0
155IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
156Formatted timestamp is : Jan 1, 1970, 5:00:00 AM
157Parsed timestamp is : 0
158------------
159
160Input timestamp is : -1200000
161------------
162
163IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
164Formatted timestamp is : Thursday, December 18, 1969 at 7:40:00 AM GMT+05:00
165Parsed timestamp is : -1200000
166IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
167Formatted timestamp is : December 18, 1969 at 7:40:00 AM GMT+5
168Parsed timestamp is : -1200000
169IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
170Formatted timestamp is : Dec 18, 1969, 7:40:00 AM
171Parsed timestamp is : -1200000
172------------
173
174Input timestamp is : 1200000
175------------
176
177IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
178Formatted timestamp is : Thursday, January 15, 1970 at 2:20:00 AM GMT+05:00
179Parsed timestamp is : 1200000
180IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
181Formatted timestamp is : January 15, 1970 at 2:20:00 AM GMT+5
182Parsed timestamp is : 1200000
183IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
184Formatted timestamp is : Jan 15, 1970, 2:20:00 AM
185Parsed timestamp is : 1200000
186------------
187
188Input timestamp is : 2200000000
189------------
190
191IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
192Formatted timestamp is : Monday, September 19, 2039 at 4:06:40 AM GMT+05:00
193Parsed timestamp is : 2200000000
194IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
195Formatted timestamp is : September 19, 2039 at 4:06:40 AM GMT+5
196Parsed timestamp is : 2200000000
197IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
198Formatted timestamp is : Sep 19, 2039, 4:06:40 AM
199Parsed timestamp is : 2200000000
200------------
201
202Input timestamp is : -2200000000
203------------
204
205IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
206Formatted timestamp is : Sunday, April 15, 1900 at 5:53:20 AM GMT+05:00
207Parsed timestamp is : -2200000000
208IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
209Formatted timestamp is : April 15, 1900 at 5:53:20 AM GMT+5
210Parsed timestamp is : -2200000000
211IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
212Formatted timestamp is : Apr 15, 1900, 5:53:20 AM
213Parsed timestamp is : -2200000000
214------------
215
216Input timestamp is : 90099999
217------------
218
219IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
220Formatted timestamp is : Thursday, November 9, 1972 at 12:46:39 AM GMT+05:00
221Parsed timestamp is : 90099999
222IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
223Formatted timestamp is : November 9, 1972 at 12:46:39 AM GMT+5
224Parsed timestamp is : 90099999
225IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
226Formatted timestamp is : Nov 9, 1972, 12:46:39 AM
227Parsed timestamp is : 90099999
228------------
229
230Input timestamp is : 3600
231------------
232
233IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
234Formatted timestamp is : Thursday, January 1, 1970 at 6:00:00 AM GMT+05:00
235Parsed timestamp is : 3600
236IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
237Formatted timestamp is : January 1, 1970 at 6:00:00 AM GMT+5
238Parsed timestamp is : 3600
239IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
240Formatted timestamp is : Jan 1, 1970, 6:00:00 AM
241Parsed timestamp is : 3600
242------------
243
244Input timestamp is : -3600
245------------
246
247IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
248Formatted timestamp is : Thursday, January 1, 1970 at 4:00:00 AM GMT+05:00
249Parsed timestamp is : -3600
250IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
251Formatted timestamp is : January 1, 1970 at 4:00:00 AM GMT+5
252Parsed timestamp is : -3600
253IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
254Formatted timestamp is : Jan 1, 1970, 4:00:00 AM
255Parsed timestamp is : -3600
256------------
257
258Input localtime is : tm_sec : '24' , tm_min : '3' , tm_hour : '19' , tm_mday : '3' , tm_mon : '3' , tm_year : '105' ,
259------------
260
261IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
262Formatted localtime_array is : Sunday, April 3, 2005 at 7:03:24 PM GMT+05:00
263Parsed array is: tm_sec : '24' , tm_min : '3' , tm_hour : '19' , tm_year : '105' , tm_mday : '3' , tm_wday : '0' , tm_yday : '93' , tm_mon : '3' , tm_isdst : '0' ,
264IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
265Formatted localtime_array is : April 3, 2005 at 7:03:24 PM GMT+5
266Parsed array is: tm_sec : '24' , tm_min : '3' , tm_hour : '19' , tm_year : '105' , tm_mday : '3' , tm_wday : '0' , tm_yday : '93' , tm_mon : '3' , tm_isdst : '0' ,
267IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
268Formatted localtime_array is : Apr 3, 2005, 7:03:24 PM
269Parsed array is: tm_sec : '24' , tm_min : '3' , tm_hour : '19' , tm_year : '105' , tm_mday : '3' , tm_wday : '0' , tm_yday : '93' , tm_mon : '3' , tm_isdst : '0' ,
270------------
271
272Input localtime is : tm_sec : '21' , tm_min : '5' , tm_hour : '7' , tm_mday : '13' , tm_mon : '7' , tm_year : '205' ,
273------------
274
275IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
276Formatted localtime_array is : Thursday, August 13, 2105 at 7:05:21 AM GMT+05:00
277Parsed array is: tm_sec : '21' , tm_min : '5' , tm_hour : '7' , tm_year : '205' , tm_mday : '13' , tm_wday : '4' , tm_yday : '225' , tm_mon : '7' , tm_isdst : '0' ,
278IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
279Formatted localtime_array is : August 13, 2105 at 7:05:21 AM GMT+5
280Parsed array is: tm_sec : '21' , tm_min : '5' , tm_hour : '7' , tm_year : '205' , tm_mday : '13' , tm_wday : '4' , tm_yday : '225' , tm_mon : '7' , tm_isdst : '0' ,
281IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
282Formatted localtime_array is : Aug 13, 2105, 7:05:21 AM
283Parsed array is: tm_sec : '21' , tm_min : '5' , tm_hour : '7' , tm_year : '205' , tm_mday : '13' , tm_wday : '4' , tm_yday : '225' , tm_mon : '7' , tm_isdst : '0' ,
284------------
285
286Input localtime is : tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_mday : '17' , tm_mon : '11' , tm_year : '-5' ,
287------------
288
289IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
290Formatted localtime_array is : Tuesday, December 17, 1895 at 12:13:11 AM GMT+05:00
291Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
292IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
293Formatted localtime_array is : December 17, 1895 at 12:13:11 AM GMT+5
294Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
295IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
296Formatted localtime_array is : Dec 17, 1895, 12:13:11 AM
297Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
298