From 6e29b055b3cbc2a46e29075608c7e82a328d5270 Mon Sep 17 00:00:00 2001 From: wei <> Date: Wed, 15 Feb 2006 07:44:51 +0000 Subject: Adding new TRatingList component. --- framework/Data/TDateTimeSimpleFormatter.php | 32 +++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'framework/Data/TDateTimeSimpleFormatter.php') diff --git a/framework/Data/TDateTimeSimpleFormatter.php b/framework/Data/TDateTimeSimpleFormatter.php index afa65bf6..ac5fb685 100644 --- a/framework/Data/TDateTimeSimpleFormatter.php +++ b/framework/Data/TDateTimeSimpleFormatter.php @@ -135,6 +135,14 @@ class TDateTimeSimpleFormatter throw new TInvalidDataValueException('invalid_date', $value); return getdate($date); } + + /** + * @return boolean true if the given value matches with the date pattern. + */ + public function isValidDate($value) + { + return !is_null($this->parse($value, false)); + } /** * Parse the string according to the pattern. @@ -142,7 +150,7 @@ class TDateTimeSimpleFormatter * @return int date time stamp * @throws TInvalidDataValueException if date string is malformed. */ - public function parse($value) + public function parse($value,$defaulToCurrentTime=true) { if(!is_string($value)) throw new TInvalidDataValueException('date_to_parse_must_be_string', $value); @@ -158,9 +166,18 @@ class TDateTimeSimpleFormatter $x=null; $y=null; $date = $this->getDate(time()); - $year = "{$date['year']}"; - $month = $date['mon']; - $day = $date['mday']; + if($defaulToCurrentTime) + { + $year = "{$date['year']}"; + $month = $date['mon']; + $day = $date['mday']; + } + else + { + $year = null; + $month = null; + $day = null; + } while ($i_format < $pattern_length) { @@ -221,8 +238,11 @@ class TDateTimeSimpleFormatter } if ($i_val != $this->length($value)) throw new TInvalidDataValueException("Pattern '{$this->pattern}' mismatch", $value); - - return mktime(0, 0, 0, $month, $day, $year); + + if(!$defaultToCurrentTime && (is_null($month) || is_null($day) || is_null($year))) + return null; + else + return mktime(0, 0, 0, $month, $day, $year); } /** -- cgit v1.2.3