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