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