From 0012117629fe0303a8056f81526bb2ace8f6e310 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 4 Jan 2024 17:06:58 +0000 Subject: [PATCH] MDL-80499 datafield_date: specify UTC time when editing field content. --- lib/outputcomponents.php | 9 ++++++--- lib/upgrade.txt | 4 ++++ mod/data/field/date/field.class.php | 23 ++++++++++++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 1998e1b4b98..d930e4a060c 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -2039,16 +2039,19 @@ class html_writer { * @param int $currenttime A default timestamp in GMT * @param int $step minute spacing * @param array $attributes - html select element attributes - * @return HTML fragment + * @param float|int|string $timezone the timezone to use to calculate the time + * {@link https://moodledev.io/docs/apis/subsystems/time#timezone} + * @return string HTML fragment */ - public static function select_time($type, $name, $currenttime = 0, $step = 5, array $attributes = null) { + public static function select_time($type, $name, $currenttime = 0, $step = 5, array $attributes = null, $timezone = 99) { global $OUTPUT; if (!$currenttime) { $currenttime = time(); } $calendartype = \core_calendar\type_factory::get_calendar_instance(); - $currentdate = $calendartype->timestamp_to_date_array($currenttime); + $currentdate = $calendartype->timestamp_to_date_array($currenttime, $timezone); + $userdatetype = $type; $timeunits = array(); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 3598b757486..09d7b6faca4 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -1,6 +1,10 @@ This files describes API changes in core libraries and APIs, information provided here is intended especially for developers. +=== 4.2.6 === + +* The `html_writer::select_time` method has a `$timezone` parameter to use when formatting the time parameter + === 4.2.5 === * The current page language is available in new `core/config` language property for Javascript modules diff --git a/mod/data/field/date/field.class.php b/mod/data/field/date/field.class.php index 97848814f44..df3c2130657 100644 --- a/mod/data/field/date/field.class.php +++ b/mod/data/field/date/field.class.php @@ -80,9 +80,26 @@ class data_field_date extends data_field_base { } $str = '
'; - $dayselector = html_writer::select_time('days', 'field_'.$this->field->id.'_day', $content); - $monthselector = html_writer::select_time('months', 'field_'.$this->field->id.'_month', $content); - $yearselector = html_writer::select_time('years', 'field_'.$this->field->id.'_year', $content); + + $dayselector = html_writer::select_time( + type: 'days', + name: "field_{$this->field->id}_day", + currenttime: $content, + timezone: 0, + ); + $monthselector = html_writer::select_time( + type: 'months', + name: "field_{$this->field->id}_month", + currenttime: $content, + timezone: 0, + ); + $yearselector = html_writer::select_time( + type: 'years', + name: "field_{$this->field->id}_year", + currenttime: $content, + timezone: 0, + ); + $str .= $dayselector . $monthselector . $yearselector; $str .= '
';