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