From 02014e728e09fe672aabb946176492b9ed51606d Mon Sep 17 00:00:00 2001 From: knut <> Date: Tue, 5 Aug 2008 18:02:53 +0000 Subject: fixed #897 --- .gitattributes | 3 +++ framework/Util/TSimpleDateFormatter.php | 13 ++++++++----- .../tickets/protected/pages/Ticket897.page | 8 ++++++++ .../tickets/protected/pages/Ticket897.php | 9 +++++++++ .../tickets/tests/Ticket897TestCase.php | 19 +++++++++++++++++++ tests/unit/Util/TSimpleDateFormatterTest.php | 5 +++++ 6 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 tests/FunctionalTests/tickets/protected/pages/Ticket897.page create mode 100644 tests/FunctionalTests/tickets/protected/pages/Ticket897.php create mode 100644 tests/FunctionalTests/tickets/tests/Ticket897TestCase.php diff --git a/.gitattributes b/.gitattributes index 1cddd32d..403ae6b8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3087,6 +3087,8 @@ tests/FunctionalTests/tickets/protected/pages/Ticket828.page -text tests/FunctionalTests/tickets/protected/pages/Ticket849.page -text tests/FunctionalTests/tickets/protected/pages/Ticket886.page -text tests/FunctionalTests/tickets/protected/pages/Ticket886.php -text +tests/FunctionalTests/tickets/protected/pages/Ticket897.page -text +tests/FunctionalTests/tickets/protected/pages/Ticket897.php -text tests/FunctionalTests/tickets/protected/pages/Ticket93.page -text tests/FunctionalTests/tickets/protected/pages/Ticket93.php -text tests/FunctionalTests/tickets/protected/pages/ToggleTest.page -text @@ -3151,6 +3153,7 @@ tests/FunctionalTests/tickets/tests/Ticket708TestCase.php -text tests/FunctionalTests/tickets/tests/Ticket72TestCase.php -text tests/FunctionalTests/tickets/tests/Ticket769TestCase.php -text tests/FunctionalTests/tickets/tests/Ticket886TestCase.php -text +tests/FunctionalTests/tickets/tests/Ticket897TestCase.php -text tests/FunctionalTests/tickets/tests/Ticket93TestCase.php -text tests/FunctionalTests/validators.php -text tests/FunctionalTests/validators/index.php -text diff --git a/framework/Util/TSimpleDateFormatter.php b/framework/Util/TSimpleDateFormatter.php index d8bf513a..d0ed4496 100644 --- a/framework/Util/TSimpleDateFormatter.php +++ b/framework/Util/TSimpleDateFormatter.php @@ -4,7 +4,7 @@ * * @author Wei Zhuo * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft * @license http://www.pradosoft.com/license/ * @version $Id$ * @package System.Util @@ -305,9 +305,12 @@ class TSimpleDateFormatter if(!$defaultToCurrentTime && ($month === null || $day === null || $year === null)) return null; else - { - $day = intval($day) <= 0 ? 1 : intval($day); - $month = intval($month) <= 0 ? 1 : intval($month); + { + if(empty($year)) { + $year = date('Y'); + } + $day = (int)$day <= 0 ? 1 : (int)$day; + $month = (int)$month <= 0 ? 1 : (int)$month; $s = Prado::createComponent('System.Util.TDateTimeStamp'); return $s->getTimeStamp(0, 0, 0, $month, $day, $year); } @@ -369,4 +372,4 @@ class TSimpleDateFormatter } } -?> +?> diff --git a/tests/FunctionalTests/tickets/protected/pages/Ticket897.page b/tests/FunctionalTests/tickets/protected/pages/Ticket897.page new file mode 100644 index 00000000..93237b98 --- /dev/null +++ b/tests/FunctionalTests/tickets/protected/pages/Ticket897.page @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/FunctionalTests/tickets/protected/pages/Ticket897.php b/tests/FunctionalTests/tickets/protected/pages/Ticket897.php new file mode 100644 index 00000000..b0b8959f --- /dev/null +++ b/tests/FunctionalTests/tickets/protected/pages/Ticket897.php @@ -0,0 +1,9 @@ +Output->Text = date('Y-m-d', $this->Date->TimeStamp); + } + +} +?> diff --git a/tests/FunctionalTests/tickets/tests/Ticket897TestCase.php b/tests/FunctionalTests/tickets/tests/Ticket897TestCase.php new file mode 100644 index 00000000..eaf4e47a --- /dev/null +++ b/tests/FunctionalTests/tickets/tests/Ticket897TestCase.php @@ -0,0 +1,19 @@ +open('tickets/index.php?page=Ticket897'); + $this->assertTitle("Verifying Ticket 897"); + $base = 'ctl0_Content_'; + + $this->select($base.'Date_month', 10); + $this->select($base.'Date_day', 22); + + $this->clickAndWait($base.'SendButton'); + $this->assertTextPresent('2008-10-22'); + } +} + +?> diff --git a/tests/unit/Util/TSimpleDateFormatterTest.php b/tests/unit/Util/TSimpleDateFormatterTest.php index ca9f6809..13ad25a9 100644 --- a/tests/unit/Util/TSimpleDateFormatterTest.php +++ b/tests/unit/Util/TSimpleDateFormatterTest.php @@ -43,6 +43,11 @@ class TSimpleDateFormatterTest extends PHPUnit_Framework_TestCase { self::assertEquals("2008-01-01", date('Y-m-d', $formatter->parse("2008"))); } + public function testMissingYearPattern() { + $formatter = new TSimpleDateFormatter("MM/dd"); + self::assertEquals("2008-10-22", date('Y-m-d', $formatter->parse("10/22"))); + } + public function testDayMonthYearOrdering() { throw new PHPUnit_Framework_IncompleteTestError(); } -- cgit v1.2.3