dateformat_localtime.phpt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. --TEST--
  2. datefmt_localtime_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--
  7. date.timezone=UTC
  8. --FILE--
  9. <?php
  10. /*
  11. * Test for the datefmt_localtime function
  12. */
  13. function ut_main()
  14. {
  15. $locale_arr = array (
  16. 'en_US_CA'
  17. );
  18. $datetype_arr = array (
  19. IntlDateFormatter::FULL,
  20. IntlDateFormatter::LONG,
  21. IntlDateFormatter::MEDIUM,
  22. IntlDateFormatter::SHORT,
  23. IntlDateFormatter::NONE
  24. );
  25. $res_str = '';
  26. $datetype_arr = array (
  27. IntlDateFormatter::FULL,
  28. IntlDateFormatter::LONG,
  29. IntlDateFormatter::MEDIUM,
  30. );
  31. $res_str = '';
  32. $text_arr = array (
  33. "Thursday, December 18, 1969 8:49:59 AM PST",
  34. "June 18, 1969 8:49:59 AM ",
  35. "12/18/69 8:49 AM",
  36. "19691218 08:49 AM"
  37. );
  38. $fmt1 = ut_datefmt_create( 'en_US_CA', IntlDateFormatter::LONG, IntlDateFormatter::LONG);
  39. $fmt2 = ut_datefmt_create( 'en_US_CA', IntlDateFormatter::MEDIUM, IntlDateFormatter::MEDIUM);
  40. $fmt3 = ut_datefmt_create( 'en_US_CA', IntlDateFormatter::FULL, IntlDateFormatter::FULL);
  41. $fmt_array = array(
  42. $fmt1 , $fmt2 ,$fmt3
  43. );
  44. $fmt_desc_array = array(
  45. "DateType::LONG, TimeType::LONG",
  46. "DateType::MEDIUM, TimeType::MEDIUM",
  47. "DateType::FULL, TimeType::FULL"
  48. );
  49. foreach( $text_arr as $text_entry){
  50. $res_str .= "\n-------------------------------\n";
  51. $res_str .= "\nInput text is : $text_entry";
  52. $cnt =0;
  53. foreach( $fmt_array as $fmt_entry ){
  54. $res_str .= "\n------------";
  55. $res_str .= "\nIntlDateFormatter : ".$fmt_desc_array[$cnt];
  56. $parse_pos = 0;
  57. $cnt++;
  58. $parsed_arr = ut_datefmt_localtime( $fmt_entry , $text_entry , $parse_pos );
  59. if( $parsed_arr){
  60. $res_str .= "\n";
  61. foreach( $parsed_arr as $key => $value){
  62. $res_str .= "$key : '$value' , ";
  63. }
  64. }
  65. /*
  66. else{
  67. //$res_str .= "No values found from LocaleTime parsing.";
  68. $res_str .= "\tError : '".intl_get_error_message()."'";
  69. }
  70. */
  71. }//end of for $fmt_array
  72. }
  73. return $res_str;
  74. }
  75. include_once( 'ut_common.inc' );
  76. // Run the test
  77. ut_run();
  78. ?>
  79. --EXPECTF--
  80. -------------------------------
  81. Input text is : Thursday, December 18, 1969 8:49:59 AM PST
  82. ------------
  83. IntlDateFormatter : DateType::LONG, TimeType::LONG
  84. ------------
  85. IntlDateFormatter : DateType::MEDIUM, TimeType::MEDIUM
  86. ------------
  87. IntlDateFormatter : DateType::FULL, TimeType::FULL
  88. tm_sec : '59' , tm_min : '49' , tm_hour : '8' , tm_year : '69' , tm_mday : '18' , tm_wday : '4' , tm_yday : '352' , tm_mon : '11' , tm_isdst : '0' ,
  89. -------------------------------
  90. Input text is : June 18, 1969 8:49:59 AM
  91. ------------
  92. IntlDateFormatter : DateType::LONG, TimeType::LONG
  93. ------------
  94. IntlDateFormatter : DateType::MEDIUM, TimeType::MEDIUM
  95. tm_sec : '59' , tm_min : '49' , tm_hour : '8' , tm_year : '69' , tm_mday : '18' , tm_wday : '3' , tm_yday : '169' , tm_mon : '5' , tm_isdst : '%d' ,
  96. ------------
  97. IntlDateFormatter : DateType::FULL, TimeType::FULL
  98. -------------------------------
  99. Input text is : 12/18/69 8:49 AM
  100. ------------
  101. IntlDateFormatter : DateType::LONG, TimeType::LONG
  102. ------------
  103. IntlDateFormatter : DateType::MEDIUM, TimeType::MEDIUM
  104. ------------
  105. IntlDateFormatter : DateType::FULL, TimeType::FULL
  106. -------------------------------
  107. Input text is : 19691218 08:49 AM
  108. ------------
  109. IntlDateFormatter : DateType::LONG, TimeType::LONG
  110. ------------
  111. IntlDateFormatter : DateType::MEDIUM, TimeType::MEDIUM
  112. ------------
  113. IntlDateFormatter : DateType::FULL, TimeType::FULL