1--TEST-- 2datefmt_parse_code() icu <= 4.2 3--SKIPIF-- 4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?> 5<?php if(version_compare(INTL_ICU_VERSION, '4.3', '<') != 1) print 'skip'; ?> 6--INI-- 7date.timezone="America/Los_Angeles" 8--FILE-- 9<?php 10 11/* 12 * Test for the datefmt_parse function 13 */ 14 15putenv('TZ=America/Los_Angeles'); 16 17function ut_main() 18{ 19 $locale_arr = array ( 20 'en_US_CA' 21 ); 22 23 $datetype_arr = array ( 24 IntlDateFormatter::FULL, 25 IntlDateFormatter::LONG, 26 IntlDateFormatter::MEDIUM, 27 IntlDateFormatter::SHORT, 28 IntlDateFormatter::NONE 29 ); 30 31 $res_str = ''; 32 33 34 $text_arr = array ( 35 // Full parsing 36 array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::FULL), 37 array("Wednesday, December 17, 1969 6:40:00 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::FULL), 38 array("Thursday, December 18, 1969 8:49:59 PM PST", IntlDateFormatter::FULL, IntlDateFormatter::FULL), 39 array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::FULL), 40 array("12/18/69 8:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::SHORT), 41 array("19691218 08:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::SHORT), 42 // Partial parsing 43 array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::NONE), 44 array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::SHORT), 45 array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::NONE), 46 array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::SHORT), 47 array("12/18/69 8:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::LONG), 48 array("19691218 08:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::LONG), 49 ); 50 51 foreach( $text_arr as $text_entry){ 52 $fmt = ut_datefmt_create( 'en_US_CA', $text_entry[1], $text_entry[2]); 53 $parse_pos = 0; 54 $parsed = ut_datefmt_parse( $fmt , $text_entry[0] , $parse_pos ); 55 56 $res_str .= "\nInput text : {$text_entry[0]} ; DF = {$text_entry[1]}; TF = {$text_entry[2]}"; 57 if( intl_get_error_code() != U_ZERO_ERROR) { 58 $res_str .= "\nError : ".intl_get_error_message(); 59 } 60 $res_str .= "\nParsed: $parsed; parse_pos : $parse_pos\n"; 61 } 62 63 return $res_str; 64 65} 66 67include_once( 'ut_common.inc' ); 68 69// Run the test 70ut_run(); 71?> 72--EXPECT-- 73 74Input text : Sunday, September 18, 2039 4:06:40 PM PT ; DF = 0; TF = 0 75Parsed: 2200000000; parse_pos : 40 76 77Input text : Wednesday, December 17, 1969 6:40:00 PM PT ; DF = 0; TF = 0 78Parsed: -1200000; parse_pos : 42 79 80Input text : Thursday, December 18, 1969 8:49:59 PM PST ; DF = 0; TF = 0 81Parsed: -1105801; parse_pos : 42 82 83Input text : December 18, 1969 8:49:59 AM PST ; DF = 1; TF = 0 84Parsed: -1149001; parse_pos : 32 85 86Input text : 12/18/69 8:49 AM ; DF = 3; TF = 3 87Parsed: -1149060; parse_pos : 16 88 89Input text : 19691218 08:49 AM ; DF = 3; TF = 3 90Error : Date parsing failed: U_PARSE_ERROR 91Parsed: ; parse_pos : 8 92 93Input text : Sunday, September 18, 2039 4:06:40 PM PT ; DF = 0; TF = -1 94Parsed: 2199942000; parse_pos : 26 95 96Input text : Sunday, September 18, 2039 4:06:40 PM PT ; DF = 0; TF = 3 97Error : Date parsing failed: U_PARSE_ERROR 98Parsed: ; parse_pos : 31 99 100Input text : December 18, 1969 8:49:59 AM PST ; DF = 1; TF = -1 101Parsed: -1180800; parse_pos : 17 102 103Input text : December 18, 1969 8:49:59 AM PST ; DF = 1; TF = 3 104Error : Date parsing failed: U_PARSE_ERROR 105Parsed: ; parse_pos : 22 106 107Input text : 12/18/69 8:49 AM ; DF = 3; TF = 1 108Error : Date parsing failed: U_PARSE_ERROR 109Parsed: ; parse_pos : 13 110 111Input text : 19691218 08:49 AM ; DF = 3; TF = 1 112Error : Date parsing failed: U_PARSE_ERROR 113Parsed: ; parse_pos : 8 114