summaryrefslogtreecommitdiff
path: root/framework/Data
diff options
context:
space:
mode:
authorwei <>2006-02-15 07:44:51 +0000
committerwei <>2006-02-15 07:44:51 +0000
commit6e29b055b3cbc2a46e29075608c7e82a328d5270 (patch)
tree13a197ad850f360125a96f5de83f1742a12e98ad /framework/Data
parentd653bda6c6217f160a4de77e3f2f0ee62096be67 (diff)
Adding new TRatingList component.
Diffstat (limited to 'framework/Data')
-rw-r--r--framework/Data/TDateTimeSimpleFormatter.php32
1 files changed, 26 insertions, 6 deletions
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);
}
/**