DateTimeZone_compare_basic1.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. --TEST--
  2. Test of compare object handler for DateTimeZone objects
  3. --FILE--
  4. <?php
  5. $timezones = array(
  6. ['+0200', '-0200'],
  7. ['EST', 'PST'],
  8. ['Europe/Amsterdam', 'Europe/Berlin']
  9. );
  10. foreach ($timezones as [$timezone1, $timezone2]) {
  11. compare_timezones($timezone1, $timezone1);
  12. compare_timezones($timezone1, $timezone2);
  13. }
  14. var_dump(new DateTimeZone('Europe/Berlin') == new DateTimeZone('CET'));
  15. function compare_timezones($timezone1, $timezone2)
  16. {
  17. $tz1 = new DateTimeZone($timezone1);
  18. $tz2 = new DateTimeZone($timezone2);
  19. echo "compare $timezone1 with $timezone2\n";
  20. echo "< ";
  21. var_dump($tz1 < $tz2);
  22. echo "= ";
  23. var_dump($tz1 == $tz2);
  24. echo "> ";
  25. var_dump($tz1 > $tz2);
  26. }
  27. // Test comparison of uninitialized DateTimeZone objects.
  28. class MyDateTimeZone extends DateTimeZone {
  29. function __construct() {
  30. // parent ctor not called
  31. }
  32. }
  33. $tz1 = new MyDateTimeZone();
  34. $tz2 = new MyDateTimeZone();
  35. try {
  36. var_dump($tz1 == $tz2);
  37. } catch (Error $e) {
  38. echo $e->getMessage(), "\n";
  39. }
  40. ?>
  41. --EXPECTF--
  42. compare +0200 with +0200
  43. < bool(false)
  44. = bool(true)
  45. > bool(false)
  46. compare +0200 with -0200
  47. < bool(false)
  48. = bool(false)
  49. > bool(false)
  50. compare EST with EST
  51. < bool(false)
  52. = bool(true)
  53. > bool(false)
  54. compare EST with PST
  55. < bool(false)
  56. = bool(false)
  57. > bool(false)
  58. compare Europe/Amsterdam with Europe/Amsterdam
  59. < bool(false)
  60. = bool(true)
  61. > bool(false)
  62. compare Europe/Amsterdam with Europe/Berlin
  63. < bool(false)
  64. = bool(false)
  65. > bool(false)
  66. Warning: main(): Trying to compare different kinds of DateTimeZone objects in %s on line %d
  67. bool(false)
  68. Trying to compare uninitialized DateTimeZone objects