Skip to content

Commit

Permalink
Make sure to always save timestamps as UTC (required for SQLite).
Browse files Browse the repository at this point in the history
  • Loading branch information
fancycode committed May 11, 2023
1 parent a835c24 commit efe9fd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ public function getRequestsForFile(File $file, bool $include_signed): array {
}

public function markRequestSignedById(string $id, string $type, string $value, \DateTime $now): bool {
$now = clone $now;
$now->setTimezone(new \DateTimeZone('UTC'));

$this->db->beginTransaction();
try {
$query = $this->db->getQueryBuilder();
Expand Down Expand Up @@ -755,6 +758,9 @@ public function getPendingSignatures() {
}

public function getCompletedRequests(\DateTime $maxDate): array {
$maxDate = clone $maxDate;
$maxDate->setTimezone(new \DateTimeZone('UTC'));

// TODO: This should be possible with a single query for both cases
// (single and multiple recipients).
$query = $this->db->getQueryBuilder();
Expand Down
2 changes: 2 additions & 0 deletions tests/php/RequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ public function testStoreRequestSingleUser() {
$this->assertEmpty($pending['multi']);

$signed = new \DateTime();
// Make sure the correct timestamp is saved, independent from the timezone.
$signed = $signed->setTimezone(new \DateTimeZone('Europe/Berlin'));
// Round to seconds, required as some databases don't store with sub-second precision.
$signed->setTimestamp($signed->getTimestamp());
$isLast = $this->requests->markRequestSignedById($id, $recipients[0]['type'], $recipients[0]['value'], $signed);
Expand Down

0 comments on commit efe9fd7

Please sign in to comment.