|
| 1 | +--TEST-- |
| 2 | +datefmt_get_pattern_code and datefmt_set_pattern_code() icu >= 4.8 |
| 3 | +--SKIPIF-- |
| 4 | +<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?> |
| 5 | +<?php if(version_compare(INTL_ICU_VERSION, '4.8') < 0) print 'skip'; ?> |
| 6 | +--FILE-- |
| 7 | + |
| 8 | +<?php |
| 9 | + |
| 10 | +/* |
| 11 | + * Test for the datefmt_get_pattern & datefmt_set_pattern function |
| 12 | + */ |
| 13 | + |
| 14 | + |
| 15 | +function ut_main() |
| 16 | +{ |
| 17 | + $pattern_arr = array ( |
| 18 | + 'DD-MM-YYYY hh:mm:ss', |
| 19 | + 'yyyy-DDD.hh:mm:ss z', |
| 20 | + "yyyy/MM/dd", |
| 21 | + "yyyyMMdd" |
| 22 | + ); |
| 23 | + |
| 24 | + $res_str = ''; |
| 25 | + |
| 26 | + $start_pattern = 'dd-MM-YY'; |
| 27 | + $res_str .= "\nCreating IntlDateFormatter with pattern = $start_pattern "; |
| 28 | + //$fmt = ut_datefmt_create( "en-US", IntlDateFormatter::SHORT, IntlDateFormatter::SHORT , 'America/New_York', IntlDateFormatter::GREGORIAN , $start_pattern ); |
| 29 | + $fmt = ut_datefmt_create( "en-US", IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'America/New_York', IntlDateFormatter::GREGORIAN , $start_pattern ); |
| 30 | + $pattern = ut_datefmt_get_pattern( $fmt); |
| 31 | + $res_str .= "\nAfter call to get_pattern : pattern= $pattern"; |
| 32 | + $formatted = ut_datefmt_format($fmt,0); |
| 33 | + $res_str .= "\nResult of formatting timestamp=0 is : \n$formatted"; |
| 34 | + |
| 35 | + |
| 36 | + foreach( $pattern_arr as $pattern_entry ) |
| 37 | + { |
| 38 | + $res_str .= "\n-------------------"; |
| 39 | + $res_str .= "\nSetting IntlDateFormatter with pattern = $pattern_entry "; |
| 40 | + ut_datefmt_set_pattern( $fmt , $pattern_entry ); |
| 41 | + $pattern = ut_datefmt_get_pattern( $fmt); |
| 42 | + $res_str .= "\nAfter call to get_pattern : pattern= $pattern"; |
| 43 | + $formatted = ut_datefmt_format($fmt,0); |
| 44 | + $res_str .= "\nResult of formatting timestamp=0 with the new pattern is : \n$formatted"; |
| 45 | + $res_str .= "\n"; |
| 46 | + |
| 47 | + } |
| 48 | + |
| 49 | + return $res_str; |
| 50 | + |
| 51 | +} |
| 52 | + |
| 53 | +include_once( 'ut_common.inc' ); |
| 54 | + |
| 55 | +// Run the test |
| 56 | +ut_run(); |
| 57 | +?> |
| 58 | +--EXPECT-- |
| 59 | +Creating IntlDateFormatter with pattern = dd-MM-YY |
| 60 | +After call to get_pattern : pattern= dd-MM-YY |
| 61 | +Result of formatting timestamp=0 is : |
| 62 | +31-12-70 |
| 63 | +------------------- |
| 64 | +Setting IntlDateFormatter with pattern = DD-MM-YYYY hh:mm:ss |
| 65 | +After call to get_pattern : pattern= DD-MM-YYYY hh:mm:ss |
| 66 | +Result of formatting timestamp=0 with the new pattern is : |
| 67 | +365-12-1970 07:00:00 |
| 68 | + |
| 69 | +------------------- |
| 70 | +Setting IntlDateFormatter with pattern = yyyy-DDD.hh:mm:ss z |
| 71 | +After call to get_pattern : pattern= yyyy-DDD.hh:mm:ss z |
| 72 | +Result of formatting timestamp=0 with the new pattern is : |
| 73 | +1969-365.07:00:00 EST |
| 74 | + |
| 75 | +------------------- |
| 76 | +Setting IntlDateFormatter with pattern = yyyy/MM/dd |
| 77 | +After call to get_pattern : pattern= yyyy/MM/dd |
| 78 | +Result of formatting timestamp=0 with the new pattern is : |
| 79 | +1969/12/31 |
| 80 | + |
| 81 | +------------------- |
| 82 | +Setting IntlDateFormatter with pattern = yyyyMMdd |
| 83 | +After call to get_pattern : pattern= yyyyMMdd |
| 84 | +Result of formatting timestamp=0 with the new pattern is : |
| 85 | +19691231 |
0 commit comments