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