mirror of
https://github.com/dg/dibi.git
synced 2025-08-01 20:00:15 +02:00
Connection: added option [result][formatTimeInterval] that sets time-interval column decoding
This commit is contained in:
@@ -50,6 +50,10 @@ class Connection implements IConnection
|
||||
* empty for decoding as Dibi\DateTime (default)
|
||||
* "..." formatted according to given format, see https://www.php.net/manual/en/datetime.format.php
|
||||
* "native" for leaving value as is
|
||||
* - formatTimeInterval => time-interval format
|
||||
* empty for decoding as DateInterval (default)
|
||||
* "..." formatted according to given format, see https://www.php.net/manual/en/dateinterval.format.php
|
||||
* "native" for leaving value as is
|
||||
* - formatJson => json format
|
||||
* "array" for decoding json as an array (default)
|
||||
* "object" for decoding json as \stdClass
|
||||
@@ -77,6 +81,7 @@ class Connection implements IConnection
|
||||
Type::DATE => $this->config['result']['formatDate'],
|
||||
Type::DATETIME => $this->config['result']['formatDateTime'],
|
||||
Type::JSON => $this->config['result']['formatJson'] ?? 'array',
|
||||
Type::TIME_INTERVAL => $this->config['result']['formatTimeInterval'] ?? null,
|
||||
];
|
||||
|
||||
// profiler
|
||||
|
@@ -498,8 +498,9 @@ class Result implements IDataSource
|
||||
|
||||
} elseif ($type === Type::TIME_INTERVAL) {
|
||||
preg_match('#^(-?)(\d+)\D(\d+)\D(\d+)\z#', $value, $m);
|
||||
$row[$key] = new \DateInterval("PT$m[2]H$m[3]M$m[4]S");
|
||||
$row[$key]->invert = (int) (bool) $m[1];
|
||||
$value = new \DateInterval("PT$m[2]H$m[3]M$m[4]S");
|
||||
$value->invert = (int) (bool) $m[1];
|
||||
$row[$key] = $format ? $value->format($format) : $value;
|
||||
|
||||
} elseif ($type === Type::BINARY) {
|
||||
$row[$key] = is_string($value)
|
||||
|
Reference in New Issue
Block a user