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