Annotation of embedaddon/php/ext/date/tests/bug54851.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Bug #54851 (DateTime::createFromFormat() doesn't interpret "D")
! 3: --INI--
! 4: date.timezone=UTC
! 5: --FILE--
! 6: <?php
! 7: $date = new DateTime("2011-05-17T22:14:12");
! 8: $date2 = DateTime::createFromFormat("D H i s", $date->format("D"). ' 0 00 00');
! 9: echo $date->format("r"), "\n";
! 10: echo $date2->format("r"), "\n";
! 11: var_dump($date->format("D") == $date2->format("D"));
! 12:
! 13: // Verify that our implementation works regardless of position
! 14: $datePre = DateTime::createFromFormat("!D d M Y", "Fri 17 may 2011");
! 15: $datePost = DateTime::createFromFormat("!d M Y D", "17 may 2011 Fri");
! 16: echo $datePre->format("r"), "\n";
! 17: echo $datePost->format("r"), "\n";
! 18: var_dump($datePre->format("Y-m-d") == $datePost->format("Y-m-d"));
! 19:
! 20: // Verify that our implementation is the same as for the constructor and
! 21: // strtotime
! 22: $date1 = new DateTime("Tuesday");
! 23: $date2 = DateTime::createFromFormat("D H i s", "Tuesday 0 00 00");
! 24: echo $date1->format('r'), "\n";
! 25: echo $date2->format('r'), "\n";
! 26: var_dump($date1->format('D') == $date2->format('D'));
! 27:
! 28: // - when the day is not the same as the day on the original date:
! 29: $date1 = DateTime::createFromFormat("!D d M Y", "Fri 19 November 2011");
! 30: $date2 = new DateTime("Fri 19 November 2011");
! 31: echo $date1->format('r'), "\n";
! 32: echo $date2->format('r'), "\n";
! 33: var_dump($date1->format('Y-m-d') == $date2->format('Y-m-d'));
! 34:
! 35: // - when the day *is* the same as the day on the original date:
! 36: $date1 = DateTime::createFromFormat("!D d M Y", "Sat 19 November 2011");
! 37: $date2 = new DateTime("Sat 19 November 2011");
! 38: echo $date1->format('r'), "\n";
! 39: echo $date2->format('r'), "\n";
! 40: var_dump($date1->format('Y-m-d') == $date2->format('Y-m-d'));
! 41: ?>
! 42: --EXPECTF--
! 43: Tue, 17 May 2011 22:14:12 +0000
! 44: Tue, %d %s %d 00:00:00 +0000
! 45: bool(true)
! 46: Fri, 20 May 2011 00:00:00 +0000
! 47: Fri, 20 May 2011 00:00:00 +0000
! 48: bool(true)
! 49: Tue, %d %s %d 00:00:00 +0000
! 50: Tue, %d %s %d 00:00:00 +0000
! 51: bool(true)
! 52: Fri, 25 Nov 2011 00:00:00 +0000
! 53: Fri, 25 Nov 2011 00:00:00 +0000
! 54: bool(true)
! 55: Sat, 19 Nov 2011 00:00:00 +0000
! 56: Sat, 19 Nov 2011 00:00:00 +0000
! 57: bool(true)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>