Annotation of embedaddon/php/ext/intl/tests/dateformat_format.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: datefmt_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:
! 13: function 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:
! 145: include_once( 'ut_common.inc' );
! 146:
! 147: // Run the test
! 148: ut_run();
! 149: ?>
! 150: --EXPECT--
! 151: ------------
! 152:
! 153: Input timestamp is : 0
! 154: ------------
! 155:
! 156: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
! 157: Formatted timestamp is : Wednesday, December 31, 1969 2:00:00 PM GMT-10:00
! 158: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
! 159: Formatted timestamp is : December 31, 1969 2:00:00 PM GMT-10:00
! 160: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
! 161: Formatted timestamp is : Dec 31, 1969 2:00:00 PM
! 162: IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
! 163: Formatted timestamp is : 12/31/69 2:00 PM
! 164: IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
! 165: Formatted timestamp is : 19691231 02:00 PM
! 166: ------------
! 167:
! 168: Input timestamp is : -1200000
! 169: ------------
! 170:
! 171: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
! 172: Formatted timestamp is : Wednesday, December 17, 1969 4:40:00 PM GMT-10:00
! 173: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
! 174: Formatted timestamp is : December 17, 1969 4:40:00 PM GMT-10:00
! 175: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
! 176: Formatted timestamp is : Dec 17, 1969 4:40:00 PM
! 177: IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
! 178: Formatted timestamp is : 12/17/69 4:40 PM
! 179: IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
! 180: Formatted timestamp is : 19691217 04:40 PM
! 181: ------------
! 182:
! 183: Input timestamp is : 1200000
! 184: ------------
! 185:
! 186: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
! 187: Formatted timestamp is : Wednesday, January 14, 1970 11:20:00 AM GMT-10:00
! 188: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
! 189: Formatted timestamp is : January 14, 1970 11:20:00 AM GMT-10:00
! 190: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
! 191: Formatted timestamp is : Jan 14, 1970 11:20:00 AM
! 192: IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
! 193: Formatted timestamp is : 1/14/70 11:20 AM
! 194: IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
! 195: Formatted timestamp is : 19700114 11:20 AM
! 196: ------------
! 197:
! 198: Input timestamp is : 2200000000
! 199: ------------
! 200:
! 201: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
! 202: Formatted timestamp is : Sunday, September 18, 2039 1:06:40 PM GMT-10:00
! 203: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
! 204: Formatted timestamp is : September 18, 2039 1:06:40 PM GMT-10:00
! 205: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
! 206: Formatted timestamp is : Sep 18, 2039 1:06:40 PM
! 207: IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
! 208: Formatted timestamp is : 9/18/39 1:06 PM
! 209: IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
! 210: Formatted timestamp is : 20390918 01:06 PM
! 211: ------------
! 212:
! 213: Input timestamp is : -2200000000
! 214: ------------
! 215:
! 216: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
! 217: Formatted timestamp is : Saturday, April 14, 1900 2:53:20 PM GMT-10:00
! 218: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
! 219: Formatted timestamp is : April 14, 1900 2:53:20 PM GMT-10:00
! 220: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
! 221: Formatted timestamp is : Apr 14, 1900 2:53:20 PM
! 222: IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
! 223: Formatted timestamp is : 4/14/00 2:53 PM
! 224: IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
! 225: Formatted timestamp is : 19000414 02:53 PM
! 226: ------------
! 227:
! 228: Input timestamp is : 90099999
! 229: ------------
! 230:
! 231: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
! 232: Formatted timestamp is : Wednesday, November 8, 1972 9:46:39 AM GMT-10:00
! 233: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
! 234: Formatted timestamp is : November 8, 1972 9:46:39 AM GMT-10:00
! 235: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
! 236: Formatted timestamp is : Nov 8, 1972 9:46:39 AM
! 237: IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
! 238: Formatted timestamp is : 11/8/72 9:46 AM
! 239: IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
! 240: Formatted timestamp is : 19721108 09:46 AM
! 241: ------------
! 242:
! 243: Input timestamp is : 3600
! 244: ------------
! 245:
! 246: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
! 247: Formatted timestamp is : Wednesday, December 31, 1969 3:00:00 PM GMT-10:00
! 248: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
! 249: Formatted timestamp is : December 31, 1969 3:00:00 PM GMT-10:00
! 250: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
! 251: Formatted timestamp is : Dec 31, 1969 3:00:00 PM
! 252: IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
! 253: Formatted timestamp is : 12/31/69 3:00 PM
! 254: IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
! 255: Formatted timestamp is : 19691231 03:00 PM
! 256: ------------
! 257:
! 258: Input timestamp is : -3600
! 259: ------------
! 260:
! 261: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
! 262: Formatted timestamp is : Wednesday, December 31, 1969 1:00:00 PM GMT-10:00
! 263: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
! 264: Formatted timestamp is : December 31, 1969 1:00:00 PM GMT-10:00
! 265: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
! 266: Formatted timestamp is : Dec 31, 1969 1:00:00 PM
! 267: IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
! 268: Formatted timestamp is : 12/31/69 1:00 PM
! 269: IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
! 270: Formatted timestamp is : 19691231 01:00 PM
! 271: ------------
! 272:
! 273: Input localtime is : tm_sec : '24' , tm_min : '3' , tm_hour : '19' , tm_mday : '3' , tm_mon : '3' , tm_year : '105' ,
! 274: ------------
! 275:
! 276: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
! 277: Formatted localtime_array is : Sunday, April 3, 2005 7:03:24 PM GMT-10:00
! 278: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
! 279: Formatted localtime_array is : April 3, 2005 7:03:24 PM GMT-10:00
! 280: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
! 281: Formatted localtime_array is : Apr 3, 2005 7:03:24 PM
! 282: IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
! 283: Formatted localtime_array is : 4/3/05 7:03 PM
! 284: IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
! 285: Formatted localtime_array is : 20050403 07:03 PM
! 286: ------------
! 287:
! 288: Input localtime is : tm_sec : '21' , tm_min : '5' , tm_hour : '7' , tm_mday : '13' , tm_mon : '4' , tm_year : '205' ,
! 289: ------------
! 290:
! 291: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
! 292: Formatted localtime_array is : Wednesday, May 13, 2105 7:05:21 AM GMT-10:00
! 293: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
! 294: Formatted localtime_array is : May 13, 2105 7:05:21 AM GMT-10:00
! 295: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
! 296: Formatted localtime_array is : May 13, 2105 7:05:21 AM
! 297: IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
! 298: Formatted localtime_array is : 5/13/05 7:05 AM
! 299: IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
! 300: Formatted localtime_array is : 21050513 07:05 AM
! 301: ------------
! 302:
! 303: Input localtime is : tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_mday : '17' , tm_mon : '11' , tm_year : '-5' ,
! 304: ------------
! 305:
! 306: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
! 307: Formatted localtime_array is : Tuesday, December 17, 1895 12:13:11 AM GMT-10:00
! 308: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
! 309: Formatted localtime_array is : December 17, 1895 12:13:11 AM GMT-10:00
! 310: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
! 311: Formatted localtime_array is : Dec 17, 1895 12:13:11 AM
! 312: IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
! 313: Formatted localtime_array is : 12/17/95 12:13 AM
! 314: IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
! 315: Formatted localtime_array is : 18951217 12:13 AM
! 316: ------------
! 317: Date is: DateTime::__set_state(array(
! 318: 'date' => '2010-01-01 01:02:03',
! 319: 'timezone_type' => 3,
! 320: 'timezone' => 'UTC',
! 321: ))
! 322: ------------
! 323: Formatted DateTime is : Thursday, December 31, 2009 3:02:03 PM GMT-10:00
! 324: ------------
! 325: Date is: DateTime::__set_state(array(
! 326: 'date' => '2010-01-01 01:02:03',
! 327: 'timezone_type' => 3,
! 328: 'timezone' => 'UTC',
! 329: ))
! 330: ------------
! 331: Formatted DateTime is : December 31, 2009 3:02:03 PM GMT-10:00
! 332: ------------
! 333: Date is: DateTime::__set_state(array(
! 334: 'date' => '2010-01-01 01:02:03',
! 335: 'timezone_type' => 3,
! 336: 'timezone' => 'UTC',
! 337: ))
! 338: ------------
! 339: Formatted DateTime is : Dec 31, 2009 3:02:03 PM
! 340: ------------
! 341: Date is: DateTime::__set_state(array(
! 342: 'date' => '2010-01-01 01:02:03',
! 343: 'timezone_type' => 3,
! 344: 'timezone' => 'UTC',
! 345: ))
! 346: ------------
! 347: Formatted DateTime is : 12/31/09 3:02 PM
! 348: ------------
! 349: Date is: DateTime::__set_state(array(
! 350: 'date' => '2010-01-01 01:02:03',
! 351: 'timezone_type' => 3,
! 352: 'timezone' => 'UTC',
! 353: ))
! 354: ------------
! 355: Formatted DateTime is : 20091231 03:02 PM
! 356: ------------
! 357: Date is: DateTime::__set_state(array(
! 358: 'date' => '2000-12-30 19:04:05',
! 359: 'timezone_type' => 3,
! 360: 'timezone' => 'America/Los_Angeles',
! 361: ))
! 362: ------------
! 363: Formatted DateTime is : Saturday, December 30, 2000 5:04:05 PM GMT-10:00
! 364: ------------
! 365: Date is: DateTime::__set_state(array(
! 366: 'date' => '2000-12-30 19:04:05',
! 367: 'timezone_type' => 3,
! 368: 'timezone' => 'America/Los_Angeles',
! 369: ))
! 370: ------------
! 371: Formatted DateTime is : December 30, 2000 5:04:05 PM GMT-10:00
! 372: ------------
! 373: Date is: DateTime::__set_state(array(
! 374: 'date' => '2000-12-30 19:04:05',
! 375: 'timezone_type' => 3,
! 376: 'timezone' => 'America/Los_Angeles',
! 377: ))
! 378: ------------
! 379: Formatted DateTime is : Dec 30, 2000 5:04:05 PM
! 380: ------------
! 381: Date is: DateTime::__set_state(array(
! 382: 'date' => '2000-12-30 19:04:05',
! 383: 'timezone_type' => 3,
! 384: 'timezone' => 'America/Los_Angeles',
! 385: ))
! 386: ------------
! 387: Formatted DateTime is : 12/30/00 5:04 PM
! 388: ------------
! 389: Date is: DateTime::__set_state(array(
! 390: 'date' => '2000-12-30 19:04:05',
! 391: 'timezone_type' => 3,
! 392: 'timezone' => 'America/Los_Angeles',
! 393: ))
! 394: ------------
! 395: Formatted DateTime is : 20001230 05:04 PM
! 396: ------------
! 397: Date is: stdClass::__set_state(array(
! 398: ))
! 399: ------------
! 400: Error while formatting as: 'datefmt_format: object must be an instance of DateTime: U_ILLEGAL_ARGUMENT_ERROR'
! 401: ------------
! 402: Date is: stdClass::__set_state(array(
! 403: ))
! 404: ------------
! 405: Error while formatting as: 'datefmt_format: object must be an instance of DateTime: U_ILLEGAL_ARGUMENT_ERROR'
! 406: ------------
! 407: Date is: stdClass::__set_state(array(
! 408: ))
! 409: ------------
! 410: Error while formatting as: 'datefmt_format: object must be an instance of DateTime: U_ILLEGAL_ARGUMENT_ERROR'
! 411: ------------
! 412: Date is: stdClass::__set_state(array(
! 413: ))
! 414: ------------
! 415: Error while formatting as: 'datefmt_format: object must be an instance of DateTime: U_ILLEGAL_ARGUMENT_ERROR'
! 416: ------------
! 417: Date is: stdClass::__set_state(array(
! 418: ))
! 419: ------------
! 420: Error while formatting as: 'datefmt_format: object must be an instance of DateTime: U_ILLEGAL_ARGUMENT_ERROR'
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>