From dd46cc65d7169d74211176d86b7a25159442a1aa Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 30 Jan 2024 14:32:25 +0000 Subject: [PATCH] MDL-80692 calendar: calculate today relative to users own timezone. Co-authored-by: Archil Abuladze --- .../external/calendar_day_exporter.php | 21 ++++++++----------- calendar/classes/external/day_exporter.php | 15 ++++++------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/calendar/classes/external/calendar_day_exporter.php b/calendar/classes/external/calendar_day_exporter.php index 8772eab3f8e0a..261e042733a45 100644 --- a/calendar/classes/external/calendar_day_exporter.php +++ b/calendar/classes/external/calendar_day_exporter.php @@ -14,22 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Contains event class for displaying the day view. - * - * @package core_calendar - * @copyright 2017 Simey Lameze - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace core_calendar\external; -defined('MOODLE_INTERNAL') || die(); - use core\external\exporter; +use core_date; +use DateTimeImmutable; use renderer_base; use moodle_url; -use \core_calendar\local\event\container; +use core_calendar\local\event\container; /** * Class for displaying the day view. @@ -209,7 +201,12 @@ protected function get_other_values(renderer_base $output) { // Need to account for user's timezone. $usernow = usergetdate(time()); - $today = new \DateTimeImmutable(); + $today = new DateTimeImmutable( + timezone: core_date::get_user_timezone_object(), + ); + + // The start time should use the day's date but the current + // time of the day (adjusted for user's timezone). $neweventtimestamp = $today->setTimestamp($date[0])->setTime( $usernow['hours'], $usernow['minutes'], diff --git a/calendar/classes/external/day_exporter.php b/calendar/classes/external/day_exporter.php index 377d2cd6e2c97..6d153d1decfaa 100644 --- a/calendar/classes/external/day_exporter.php +++ b/calendar/classes/external/day_exporter.php @@ -14,14 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Contains event class for displaying the day view. - * - * @package core_calendar - * @copyright 2017 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); @@ -29,6 +21,8 @@ require_once($CFG->dirroot . '/calendar/lib.php'); use core\external\exporter; +use core_date; +use DateTimeImmutable; use renderer_base; use moodle_url; @@ -169,7 +163,10 @@ protected function get_other_values(renderer_base $output) { $timestamp = $this->data[0]; // Need to account for user's timezone. $usernow = usergetdate(time()); - $today = new \DateTimeImmutable(); + $today = new DateTimeImmutable( + timezone: core_date::get_user_timezone_object(), + ); + // The start time should use the day's date but the current // time of the day (adjusted for user's timezone). $neweventstarttime = $today->setTimestamp($timestamp)->setTime(