Skip to content

Commit 85ca8b5

Browse files
[Lock] Fix using fractional TTLs on all platforms
1 parent b832b3e commit 85ca8b5

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

Store/DoctrineDbalStore.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ private function getCurrentTimestampStatement(): string
254254
$platform = $this->conn->getDatabasePlatform();
255255

256256
return match (true) {
257-
$platform instanceof \Doctrine\DBAL\Platforms\MySQLPlatform,
258-
$platform instanceof \Doctrine\DBAL\Platforms\MySQL57Platform => 'UNIX_TIMESTAMP()',
259-
$platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform => 'strftime(\'%s\',\'now\')',
260-
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform,
261-
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQL94Platform => 'CAST(EXTRACT(epoch FROM NOW()) AS DOUBLE PRECISION)',
262-
$platform instanceof \Doctrine\DBAL\Platforms\OraclePlatform => '(SYSDATE - TO_DATE(\'19700101\',\'yyyymmdd\'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone), 1, 3))*3600',
263-
$platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform,
264-
$platform instanceof \Doctrine\DBAL\Platforms\SQLServer2012Platform => 'DATEDIFF(s, \'1970-01-01\', GETUTCDATE())',
265-
default => (string) time(),
257+
$platform instanceof \Doctrine\DBAL\Platforms\MySQL57Platform,
258+
$platform instanceof \Doctrine\DBAL\Platforms\MySQLPlatform => 'UNIX_TIMESTAMP(NOW(6))',
259+
$platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform => "(julianday('now') - 2440587.5) * 86400.0",
260+
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQL94Platform,
261+
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform => 'CAST(EXTRACT(epoch FROM NOW()) AS DOUBLE PRECISION)',
262+
$platform instanceof \Doctrine\DBAL\Platforms\OraclePlatform => "(CAST(systimestamp AT TIME ZONE 'UTC' AS DATE) - DATE '1970-01-01') * 86400 + TO_NUMBER(TO_CHAR(systimestamp AT TIME ZONE 'UTC', 'SSSSS.FF'))",
263+
$platform instanceof \Doctrine\DBAL\Platforms\SQLServer2012Platform,
264+
$platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform => "CAST(DATEDIFF_BIG(ms, '1970-01-01', SYSUTCDATETIME()) AS FLOAT) / 1000.0",
265+
default => (new \DateTimeImmutable())->format('U.u'),
266266
};
267267
}
268268

Store/PdoStore.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ private function getDriver(): string
229229
private function getCurrentTimestampStatement(): string
230230
{
231231
return match ($this->getDriver()) {
232-
'mysql' => 'UNIX_TIMESTAMP()',
233-
'sqlite' => 'strftime(\'%s\',\'now\')',
234-
'pgsql' => 'CAST(EXTRACT(epoch FROM NOW()) AS INT)',
235-
'oci' => '(SYSDATE - TO_DATE(\'19700101\',\'yyyymmdd\'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone), 1, 3))*3600',
236-
'sqlsrv' => 'DATEDIFF(s, \'1970-01-01\', GETUTCDATE())',
237-
default => (string) time(),
232+
'mysql' => 'UNIX_TIMESTAMP(NOW(6))',
233+
'sqlite' => "(julianday('now') - 2440587.5) * 86400.0",
234+
'pgsql' => 'CAST(EXTRACT(epoch FROM NOW()) AS DOUBLE PRECISION)',
235+
'oci' => "(CAST(systimestamp AT TIME ZONE 'UTC' AS DATE) - DATE '1970-01-01') * 86400 + TO_NUMBER(TO_CHAR(systimestamp AT TIME ZONE 'UTC', 'SSSSS.FF'))",
236+
'sqlsrv' => "CAST(DATEDIFF_BIG(ms, '1970-01-01', SYSUTCDATETIME()) AS FLOAT) / 1000.0",
237+
default => (new \DateTimeImmutable())->format('U.u'),
238238
};
239239
}
240240

0 commit comments

Comments
 (0)