mirror of
https://github.com/dg/dibi.git
synced 2025-01-17 22:28:50 +01:00
Connection: added option [result][formatTimeInterval] that sets time-interval column decoding
This commit is contained in:
parent
98563d8165
commit
5fa5acb724
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user