Skip to content

Commit

Permalink
Merge branch 'MDL-80499-402' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_402_STABLE
  • Loading branch information
HuongNV13 committed Jan 22, 2024
2 parents c63571c + 0012117 commit 609761b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/outputcomponents.php
Expand Up @@ -2039,16 +2039,19 @@ private static function select_optgroup($groupname, $options, array $selected) {
* @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();

Expand Down
4 changes: 4 additions & 0 deletions 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
Expand Down
23 changes: 20 additions & 3 deletions mod/data/field/date/field.class.php
Expand Up @@ -80,9 +80,26 @@ function display_add_field($recordid = 0, $formdata = null) {
}

$str = '<div title="'.s($this->field->description).'" class="mod-data-input form-inline">';
$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 .= '</div>';

Expand Down

0 comments on commit 609761b

Please sign in to comment.