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