1--TEST--
2datefmt_format_code()
3--SKIPIF--
4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5<?php if (version_compare(INTL_ICU_VERSION, '51.2') < 0 || version_compare(INTL_ICU_VERSION, '52.1') >= 0) die('skip for ICU >= 51.2 && ICU < 52.1'); ?>
6--FILE--
7<?php
8
9//ini_set("intl.error_level", E_WARNING);
10
11/*
12 * Test for the datefmt_format  function
13 */
14
15
16function ut_main()
17{
18	$timezone = 'GMT-10: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                IntlDateFormatter::SHORT,
29                IntlDateFormatter::NONE
30        );
31
32        $res_str = '';
33
34
35	$time_arr = array (
36		0,
37		-1200000,
38		1200000,
39		2200000000.0,
40		-2200000000.0,
41		90099999,
42		3600,
43		-3600
44	);
45
46	$localtime_arr1 = array (
47	    'tm_sec' => 24 ,
48	    'tm_min' => 3,
49	    'tm_hour' => 19,
50	    'tm_mday' => 3,
51	    'tm_mon' => 3,
52	    'tm_year' => 105,
53	);
54	$localtime_arr2 = array (
55	    'tm_sec' => 21,
56	    'tm_min' => 5,
57	    'tm_hour' => 7,
58	    'tm_mday' => 13,
59	    'tm_mon' => 4,
60	    'tm_year' => 205,
61	);
62	$localtime_arr3 = array (
63            'tm_sec' => 11,
64            'tm_min' => 13,
65            'tm_hour' => 0,
66            'tm_mday' => 17,
67            'tm_mon' => 11,
68            'tm_year' => -5
69        );
70
71	$localtime_arr = array (
72		$localtime_arr1,
73		$localtime_arr2,
74		$localtime_arr3
75	);
76
77	$d1 = new DateTime("2010-01-01 01:02:03", new DateTimeZone("UTC"));
78	$d2 = new DateTime("2000-12-31 03:04:05", new DateTimeZone("UTC"));
79	$d2->setTimezone(new DateTimeZone("PDT"));
80	$dates = array(
81		$d1,
82		$d2,
83		new StdClass(),
84	);
85
86	//Test format with input as a timestamp : integer
87	foreach( $time_arr as $timestamp_entry){
88		$res_str .= "\n------------\n";
89		$res_str .= "\nInput timestamp is : $timestamp_entry";
90		$res_str .= "\n------------\n";
91		foreach( $locale_arr as $locale_entry ){
92			foreach( $datetype_arr as $datetype_entry )
93	{
94		$res_str .= "\nIntlDateFormatter locale= $locale_entry ,datetype = $datetype_entry ,timetype =$datetype_entry ";
95		$fmt = ut_datefmt_create( $locale_entry , $datetype_entry ,$datetype_entry, $timezone, IntlDateFormatter::GREGORIAN);
96		$formatted = ut_datefmt_format( $fmt , $timestamp_entry);
97		$res_str .= "\nFormatted timestamp is : $formatted";
98	}
99	}
100	}
101
102	//Test format with input as a localtime :array
103	foreach( $localtime_arr as $localtime_entry){
104		$res_str .= "\n------------\n";
105		$res_str .= "\nInput localtime is : ";
106		foreach( $localtime_entry as $key => $value){
107                    $res_str .= "$key : '$value' , ";
108		}
109
110		$res_str .= "\n------------\n";
111		foreach( $locale_arr as $locale_entry ){
112			foreach( $datetype_arr as $datetype_entry )
113	{
114		$res_str .= "\nIntlDateFormatter locale= $locale_entry ,datetype = $datetype_entry ,timetype =$datetype_entry ";
115		$fmt = ut_datefmt_create( $locale_entry , $datetype_entry ,$datetype_entry, $timezone, IntlDateFormatter::GREGORIAN );
116		$formatted1 = ut_datefmt_format( $fmt , $localtime_entry);
117		if( intl_get_error_code() == U_ZERO_ERROR){
118			$res_str .= "\nFormatted localtime_array is : $formatted1";
119		}else{
120			$res_str .= "\nError while formatting as: '".intl_get_error_message()."'";
121		}
122	}
123	}
124	}
125
126	foreach($dates as $date_entry) {
127		foreach( $locale_arr as $locale_entry ){
128			foreach( $datetype_arr as $datetype_entry ) {
129				$res_str .= "\n------------";
130				$res_str .= "\nDate is: ".var_export($date_entry, true);
131				$res_str .= "\n------------";
132
133				$fmt = ut_datefmt_create( $locale_entry , $datetype_entry ,$datetype_entry, $timezone, IntlDateFormatter::GREGORIAN );
134				$formatted1 = ut_datefmt_format( $fmt , $date_entry);
135				if( intl_get_error_code() == U_ZERO_ERROR){
136					$res_str .= "\nFormatted DateTime is : $formatted1";
137				}else{
138					$res_str .= "\nError while formatting as: '".intl_get_error_message()."'";
139				}
140			}
141		}
142	}
143
144	return $res_str;
145
146}
147
148include_once( 'ut_common.inc' );
149
150// Run the test
151ut_run();
152?>
153--EXPECT--
154------------
155
156Input timestamp is : 0
157------------
158
159IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
160Formatted timestamp is : Wednesday, December 31, 1969 at 2:00:00 PM GMT-10:00
161IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
162Formatted timestamp is : December 31, 1969 at 2:00:00 PM GMT-10
163IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
164Formatted timestamp is : Dec 31, 1969, 2:00:00 PM
165IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
166Formatted timestamp is : 12/31/69, 2:00 PM
167IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
168Formatted timestamp is : 19691231 02:00 PM
169------------
170
171Input timestamp is : -1200000
172------------
173
174IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
175Formatted timestamp is : Wednesday, December 17, 1969 at 4:40:00 PM GMT-10:00
176IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
177Formatted timestamp is : December 17, 1969 at 4:40:00 PM GMT-10
178IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
179Formatted timestamp is : Dec 17, 1969, 4:40:00 PM
180IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
181Formatted timestamp is : 12/17/69, 4:40 PM
182IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
183Formatted timestamp is : 19691217 04:40 PM
184------------
185
186Input timestamp is : 1200000
187------------
188
189IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
190Formatted timestamp is : Wednesday, January 14, 1970 at 11:20:00 AM GMT-10:00
191IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
192Formatted timestamp is : January 14, 1970 at 11:20:00 AM GMT-10
193IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
194Formatted timestamp is : Jan 14, 1970, 11:20:00 AM
195IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
196Formatted timestamp is : 1/14/70, 11:20 AM
197IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
198Formatted timestamp is : 19700114 11:20 AM
199------------
200
201Input timestamp is : 2200000000
202------------
203
204IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
205Formatted timestamp is : Sunday, September 18, 2039 at 1:06:40 PM GMT-10:00
206IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
207Formatted timestamp is : September 18, 2039 at 1:06:40 PM GMT-10
208IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
209Formatted timestamp is : Sep 18, 2039, 1:06:40 PM
210IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
211Formatted timestamp is : 9/18/39, 1:06 PM
212IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
213Formatted timestamp is : 20390918 01:06 PM
214------------
215
216Input timestamp is : -2200000000
217------------
218
219IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
220Formatted timestamp is : Saturday, April 14, 1900 at 2:53:20 PM GMT-10:00
221IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
222Formatted timestamp is : April 14, 1900 at 2:53:20 PM GMT-10
223IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
224Formatted timestamp is : Apr 14, 1900, 2:53:20 PM
225IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
226Formatted timestamp is : 4/14/00, 2:53 PM
227IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
228Formatted timestamp is : 19000414 02:53 PM
229------------
230
231Input timestamp is : 90099999
232------------
233
234IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
235Formatted timestamp is : Wednesday, November 8, 1972 at 9:46:39 AM GMT-10:00
236IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
237Formatted timestamp is : November 8, 1972 at 9:46:39 AM GMT-10
238IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
239Formatted timestamp is : Nov 8, 1972, 9:46:39 AM
240IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
241Formatted timestamp is : 11/8/72, 9:46 AM
242IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
243Formatted timestamp is : 19721108 09:46 AM
244------------
245
246Input timestamp is : 3600
247------------
248
249IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
250Formatted timestamp is : Wednesday, December 31, 1969 at 3:00:00 PM GMT-10:00
251IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
252Formatted timestamp is : December 31, 1969 at 3:00:00 PM GMT-10
253IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
254Formatted timestamp is : Dec 31, 1969, 3:00:00 PM
255IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
256Formatted timestamp is : 12/31/69, 3:00 PM
257IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
258Formatted timestamp is : 19691231 03:00 PM
259------------
260
261Input timestamp is : -3600
262------------
263
264IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
265Formatted timestamp is : Wednesday, December 31, 1969 at 1:00:00 PM GMT-10:00
266IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
267Formatted timestamp is : December 31, 1969 at 1:00:00 PM GMT-10
268IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
269Formatted timestamp is : Dec 31, 1969, 1:00:00 PM
270IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
271Formatted timestamp is : 12/31/69, 1:00 PM
272IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
273Formatted timestamp is : 19691231 01:00 PM
274------------
275
276Input localtime is : tm_sec : '24' , tm_min : '3' , tm_hour : '19' , tm_mday : '3' , tm_mon : '3' , tm_year : '105' ,
277------------
278
279IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
280Formatted localtime_array is : Sunday, April 3, 2005 at 7:03:24 PM GMT-10:00
281IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
282Formatted localtime_array is : April 3, 2005 at 7:03:24 PM GMT-10
283IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
284Formatted localtime_array is : Apr 3, 2005, 7:03:24 PM
285IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
286Formatted localtime_array is : 4/3/05, 7:03 PM
287IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
288Formatted localtime_array is : 20050403 07:03 PM
289------------
290
291Input localtime is : tm_sec : '21' , tm_min : '5' , tm_hour : '7' , tm_mday : '13' , tm_mon : '4' , tm_year : '205' ,
292------------
293
294IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
295Formatted localtime_array is : Wednesday, May 13, 2105 at 7:05:21 AM GMT-10:00
296IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
297Formatted localtime_array is : May 13, 2105 at 7:05:21 AM GMT-10
298IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
299Formatted localtime_array is : May 13, 2105, 7:05:21 AM
300IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
301Formatted localtime_array is : 5/13/05, 7:05 AM
302IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
303Formatted localtime_array is : 21050513 07:05 AM
304------------
305
306Input localtime is : tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_mday : '17' , tm_mon : '11' , tm_year : '-5' ,
307------------
308
309IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
310Formatted localtime_array is : Tuesday, December 17, 1895 at 12:13:11 AM GMT-10:00
311IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
312Formatted localtime_array is : December 17, 1895 at 12:13:11 AM GMT-10
313IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
314Formatted localtime_array is : Dec 17, 1895, 12:13:11 AM
315IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
316Formatted localtime_array is : 12/17/95, 12:13 AM
317IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
318Formatted localtime_array is : 18951217 12:13 AM
319------------
320Date is: DateTime::__set_state(array(
321   'date' => '2010-01-01 01:02:03.000000',
322   'timezone_type' => 3,
323   'timezone' => 'UTC',
324))
325------------
326Formatted DateTime is : Thursday, December 31, 2009 at 3:02:03 PM GMT-10:00
327------------
328Date is: DateTime::__set_state(array(
329   'date' => '2010-01-01 01:02:03.000000',
330   'timezone_type' => 3,
331   'timezone' => 'UTC',
332))
333------------
334Formatted DateTime is : December 31, 2009 at 3:02:03 PM GMT-10
335------------
336Date is: DateTime::__set_state(array(
337   'date' => '2010-01-01 01:02:03.000000',
338   'timezone_type' => 3,
339   'timezone' => 'UTC',
340))
341------------
342Formatted DateTime is : Dec 31, 2009, 3:02:03 PM
343------------
344Date is: DateTime::__set_state(array(
345   'date' => '2010-01-01 01:02:03.000000',
346   'timezone_type' => 3,
347   'timezone' => 'UTC',
348))
349------------
350Formatted DateTime is : 12/31/09, 3:02 PM
351------------
352Date is: DateTime::__set_state(array(
353   'date' => '2010-01-01 01:02:03.000000',
354   'timezone_type' => 3,
355   'timezone' => 'UTC',
356))
357------------
358Formatted DateTime is : 20091231 03:02 PM
359------------
360Date is: DateTime::__set_state(array(
361   'date' => '2000-12-30 19:04:05.000000',
362   'timezone_type' => 3,
363   'timezone' => 'America/Los_Angeles',
364))
365------------
366Formatted DateTime is : Saturday, December 30, 2000 at 5:04:05 PM GMT-10:00
367------------
368Date is: DateTime::__set_state(array(
369   'date' => '2000-12-30 19:04:05.000000',
370   'timezone_type' => 3,
371   'timezone' => 'America/Los_Angeles',
372))
373------------
374Formatted DateTime is : December 30, 2000 at 5:04:05 PM GMT-10
375------------
376Date is: DateTime::__set_state(array(
377   'date' => '2000-12-30 19:04:05.000000',
378   'timezone_type' => 3,
379   'timezone' => 'America/Los_Angeles',
380))
381------------
382Formatted DateTime is : Dec 30, 2000, 5:04:05 PM
383------------
384Date is: DateTime::__set_state(array(
385   'date' => '2000-12-30 19:04:05.000000',
386   'timezone_type' => 3,
387   'timezone' => 'America/Los_Angeles',
388))
389------------
390Formatted DateTime is : 12/30/00, 5:04 PM
391------------
392Date is: DateTime::__set_state(array(
393   'date' => '2000-12-30 19:04:05.000000',
394   'timezone_type' => 3,
395   'timezone' => 'America/Los_Angeles',
396))
397------------
398Formatted DateTime is : 20001230 05:04 PM
399------------
400Date is: stdClass::__set_state(array(
401))
402------------
403Error while formatting as: 'datefmt_format: invalid object type for date/time (only IntlCalendar and DateTime permitted): U_ILLEGAL_ARGUMENT_ERROR'
404------------
405Date is: stdClass::__set_state(array(
406))
407------------
408Error while formatting as: 'datefmt_format: invalid object type for date/time (only IntlCalendar and DateTime permitted): U_ILLEGAL_ARGUMENT_ERROR'
409------------
410Date is: stdClass::__set_state(array(
411))
412------------
413Error while formatting as: 'datefmt_format: invalid object type for date/time (only IntlCalendar and DateTime permitted): U_ILLEGAL_ARGUMENT_ERROR'
414------------
415Date is: stdClass::__set_state(array(
416))
417------------
418Error while formatting as: 'datefmt_format: invalid object type for date/time (only IntlCalendar and DateTime permitted): U_ILLEGAL_ARGUMENT_ERROR'
419------------
420Date is: stdClass::__set_state(array(
421))
422------------
423Error while formatting as: 'datefmt_format: invalid object type for date/time (only IntlCalendar and DateTime permitted): U_ILLEGAL_ARGUMENT_ERROR'
424