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