Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DibiRow::asDateTime() added $format parameter

  • Loading branch information...
commit ec1a1ec5b9b8b0a450777bee97ecb01fb01f03d6 1 parent 55cd98e
@dg authored
Showing with 8 additions and 7 deletions.
  1. +8 −7 dibi/libs/DibiRow.php
View
15 dibi/libs/DibiRow.php
@@ -34,14 +34,17 @@ public function __construct($arr)
/**
* Converts value to DateTime object.
* @param string key
+ * @param string format
* @return DateTime
*/
- public function asDateTime($key)
+ public function asDateTime($key, $format = NULL)
{
$time = $this[$key];
- return (int) $time === 0 // '', NULL, FALSE, '0000-00-00', ...
- ? NULL
- : new DateTime53(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
+ if ((int) $time === 0) { // '', NULL, FALSE, '0000-00-00', ...
+ return NULL;
+ }
+ $dt = new DateTime53(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
+ return $format === NULL ? $dt : $dt->format($format);
}
@@ -95,10 +98,8 @@ public function asDate($key, $format = NULL)
{
if ($format === NULL) {
return $this->asTimestamp($key);
- } elseif ($format === TRUE) {
- return $this->asDateTime($key);
} else {
- return $this->asDateTime($key)->format($format);
+ return $this->asDateTime($key, $format === TRUE ? NULL : $format);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.