From fca896d4dfc84d09f896500e556e25b2015263d4 Mon Sep 17 00:00:00 2001 From: Marty Date: Thu, 23 Jan 2025 14:39:42 -0500 Subject: [PATCH] MDL-81195 core_course: allow for daylight savings In timezones where daylight savings time is used, courses that start on a Monday at 00:00 would display the week headings incorrectly during the change forward. When the time changes backwards, courses that have a start time of Sunday at 23:00 also have a mislabeled week. This attempts to use the DateTime() library, along with the user's local timezone setting to display the correct day, rather than just subtracting 86400. --- course/format/weeks/lib.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/course/format/weeks/lib.php b/course/format/weeks/lib.php index 31e54fce94c..5b65792f3e4 100644 --- a/course/format/weeks/lib.php +++ b/course/format/weeks/lib.php @@ -93,8 +93,12 @@ class format_weeks extends core_courseformat\base { } else { $dates = $this->get_section_dates($section); - // We subtract 24 hours for display purposes. - $dates->end = ($dates->end - 86400); + // Find the prior day for display purposes. + $enddate = new DateTime(); + $enddate->setTimezone(core_date::get_user_timezone_object()); + $enddate->setTimestamp(intval($dates->end)); + $enddate->modify('-1 day'); + $dates->end = $enddate->getTimestamp(); $dateformat = get_string('strftimedateshort'); $weekday = userdate($dates->start, $dateformat);