From 01983d50d45fdafe49d0d5a18c3931d20a60c35e Mon Sep 17 00:00:00 2001 From: Benjamin Gaussorgues Date: Wed, 7 Feb 2024 12:06:12 +0100 Subject: feat(share): save date and time for expiration Because of timezones, not saving time can lead to unexpected behaviour when sharing an item sooner than timezone offset Example: sharing a file before 9am when in UTC+9 Signed-off-by: Benjamin Gaussorgues --- apps/files_sharing/lib/Controller/ShareAPIController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'apps/files_sharing/lib/Controller') diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 71d21cfb55c..fb9019742d2 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -240,6 +240,7 @@ class ShareAPIController extends OCSController { $expiration = $share->getExpirationDate(); if ($expiration !== null) { + $expiration->setTimezone($this->dateTimeZone->getTimeZone()); $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); } @@ -1695,12 +1696,14 @@ class ShareAPIController extends OCSController { private function parseDate(string $expireDate): \DateTime { try { $date = new \DateTime(trim($expireDate, "\""), $this->dateTimeZone->getTimeZone()); + // Make sure it expires at midnight in owner timezone + $date->setTime(0, 0, 0); } catch (\Exception $e) { throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); } + // Use server timezone to store the date $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); - $date->setTime(0, 0, 0); return $date; } -- cgit v1.2.3