aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/Controller
diff options
context:
space:
mode:
authorBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2024-02-07 12:06:12 +0100
committerBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2024-02-22 11:26:01 +0100
commit01983d50d45fdafe49d0d5a18c3931d20a60c35e (patch)
treeecd81d2b4cf0ac403c31b0cbd614cf160fc6c929 /apps/files_sharing/lib/Controller
parent1a26b32d25d6915a05ce195982f23a3a1a6d67b8 (diff)
downloadnextcloud-server-01983d50d45fdafe49d0d5a18c3931d20a60c35e.tar.gz
nextcloud-server-01983d50d45fdafe49d0d5a18c3931d20a60c35e.zip
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 <benjamin.gaussorgues@nextcloud.com>
Diffstat (limited to 'apps/files_sharing/lib/Controller')
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php5
1 files changed, 4 insertions, 1 deletions
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;
}