From 11d9e3f39458c4870ca722ba1d3db0d5bba754dc Mon Sep 17 00:00:00 2001 From: ctrlaltca <> Date: Sun, 6 Jan 2013 19:12:45 +0000 Subject: fix #44 --- framework/Util/TDateTimeStamp.php | 26 +++++++++++++++++++++++++- framework/Util/TSimpleDateFormatter.php | 11 ++--------- 2 files changed, 27 insertions(+), 10 deletions(-) (limited to 'framework') diff --git a/framework/Util/TDateTimeStamp.php b/framework/Util/TDateTimeStamp.php index a7a43b3c..f5f76004 100644 --- a/framework/Util/TDateTimeStamp.php +++ b/framework/Util/TDateTimeStamp.php @@ -102,6 +102,30 @@ class TDateTimeStamp return (int) $dt->format('Z'); } + /** + * @return array an array with date info. + */ + function parseDate($txt=false) + { + if ($txt === false) return getdate(); + + $dt = new DateTime($txt); + + return array( + 'seconds' => (int) $dt->format('s'), + 'minutes' => (int) $dt->format('i'), + 'hours' => (int) $dt->format('G'), + 'mday' => (int) $dt->format('j'), + 'wday' => (int) $dt->format('w'), + 'mon' => (int) $dt->format('n'), + 'year' => (int) $dt->format('Y'), + 'yday' => (int) $dt->format('z'), + 'weekday' => $dt->format('l'), + 'month' => $dt->format('F'), + 0 => (int) $dt->format('U'), + ); + } + /** * @return array an array with date info. */ @@ -123,7 +147,7 @@ class TDateTimeStamp 'yday' => (int) $dt->format('z'), 'weekday' => $dt->format('l'), 'month' => $dt->format('F'), - 0 => (int) $d + 0 => (int) $dt->format('U'), ); } diff --git a/framework/Util/TSimpleDateFormatter.php b/framework/Util/TSimpleDateFormatter.php index 8b17048a..a1a1842a 100644 --- a/framework/Util/TSimpleDateFormatter.php +++ b/framework/Util/TSimpleDateFormatter.php @@ -173,15 +173,8 @@ class TSimpleDateFormatter */ private function getDate($value) { - if(!is_string($value)) - { - $s = Prado::createComponent('System.Util.TDateTimeStamp'); - return $s->getDate($value); - } - $date = @strtotime($value); - if($date < 0) - throw new TInvalidDataValueException('invalid_date', $value); - return @getdate($date); + $s = Prado::createComponent('System.Util.TDateTimeStamp'); + return $s->parseDate($value); } /** -- cgit v1.2.3