diff --git a/lib/private/Streamer.php b/lib/private/Streamer.php index e579c42c0d7..ca03295b026 100644 --- a/lib/private/Streamer.php +++ b/lib/private/Streamer.php @@ -14,6 +14,7 @@ use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; +use OCP\IDateTimeZone; use OCP\IRequest; use ownCloud\TarStreamer\TarStreamer; use Psr\Log\LoggerInterface; @@ -156,7 +157,7 @@ class Streamer { $options = []; if ($time) { $options = [ - 'timestamp' => $time + 'timestamp' => $this->fixTimestamp($time), ]; } @@ -176,7 +177,7 @@ class Streamer { public function addEmptyDir(string $dirName, int $timestamp = 0): bool { $options = null; if ($timestamp > 0) { - $options = ['timestamp' => $timestamp]; + $options = ['timestamp' => $this->fixTimestamp($timestamp)]; } return $this->streamerInstance->addEmptyDir($dirName, $options); @@ -191,4 +192,14 @@ class Streamer { public function finalize() { return $this->streamerInstance->finalize(); } + + private function fixTimestamp(int $timestamp): int { + if ($this->streamerInstance instanceof ZipStreamer) { + // Zip does not support any timezone information + // while tar is interpreted as Unix time the Zip time is interpreted as local time of the user... + $zone = \OCP\Server::get(IDateTimeZone::class)->getTimeZone($timestamp); + $timestamp += $zone->getOffset(new \DateTimeImmutable('@' . (string)$timestamp)); + } + return $timestamp; + } }