Skip to content

Commit 419cd14

Browse files
authored
Merge pull request #101 from ydb-platform/fix-timestamp
Added microseconds in Timestamp type
2 parents e1358b5 + 04f3182 commit 419cd14

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.9.0
2+
3+
* added microseconds in Timestamp type
4+
15
## 1.8.2
26
* fixed discovery on exception
37
* fixed logger in EnvironCredentials

src/QueryResult.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,13 @@ protected function fillRows($rows)
194194
break;
195195

196196
case 'TIMESTAMP':
197-
$_row[$column['name']] = is_numeric($value) ? date('Y-m-d H:i:s', $value/1000000) : $value;
197+
if(is_numeric($value)){
198+
$value = number_format($value/1000000,6,'.','');
199+
$date = DateTime::createFromFormat('U.u', $value);
200+
$_row[$column['name']] = $date->format('Y-m-d H:i:s.u');
201+
} else {
202+
$_row[$column['name']] = $value;
203+
}
198204
break;
199205

200206
case 'DATETIME':

src/Types/TimestampType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
class TimestampType extends DatetimeType
99
{
10+
/**
11+
* @var string
12+
*/
13+
protected static $datetime_format = 'Y-m-d\TH:i:s.u\Z';
1014

1115
protected $ydb_key_name = "uint64_value";
1216

@@ -25,6 +29,6 @@ protected function getYqlString()
2529
protected function getYdbValue()
2630
{
2731
$value = new DateTime($this->value);
28-
return $value->getTimestamp() * 1000000;
32+
return $value->format("U.u") * 1000000;
2933
}
3034
}

src/Version.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
const MAJOR = 1;
3-
const MINOR = 8;
4-
const PATCH = 2;
2+
const MAJOR = "1";
3+
const MINOR = "9";
4+
const PATCH = "0";
55

tests/CheckTypeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ public function test(){
146146
"Timestamp" => [
147147
"class" => TimestampType::class,
148148
"values" => [
149-
"2023-06-14 17:12:15"
149+
"2023-06-14 17:12:15.023476",
150+
"2023-06-14 17:12:15.000000"
150151
]
151152
]
152153
];

0 commit comments

Comments
 (0)