Skip to content

Commit 7d9000c

Browse files
committed
fixup! MDL-83873 core_calendar: Deprecating lib functions
1 parent 0bdf0aa commit 7d9000c

File tree

1 file changed

+17
-93
lines changed

1 file changed

+17
-93
lines changed

calendar/deprecatedlib.php

+17-93
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
defined('MOODLE_INTERNAL') || die();
2626

27+
use core_calendar\output\humandate;
28+
use core_calendar\output\humantimeperiod;
29+
2730
/**
2831
* Return the representation day.
2932
*
@@ -92,27 +95,16 @@ function calendar_day_representation($tstamp, $now = false, $usecommonwords = tr
9295
mdl: 'MDL-83873',
9396
)]
9497
function calendar_time_representation($time) {
95-
static $langtimeformat = null;
96-
9798
\core\deprecation::emit_deprecation_if_present(__FUNCTION__);
9899

99-
if ($langtimeformat === null) {
100-
$langtimeformat = get_string('strftimetime');
101-
}
102-
103-
$timeformat = get_user_preferences('calendar_timeformat');
104-
if (empty($timeformat)) {
105-
$timeformat = get_config(null, 'calendar_site_timeformat');
106-
}
100+
global $OUTPUT;
107101

108-
// Allow language customization of selected time format.
109-
if ($timeformat === CALENDAR_TF_12) {
110-
$timeformat = get_string('strftimetime12', 'langconfig');
111-
} else if ($timeformat === CALENDAR_TF_24) {
112-
$timeformat = get_string('strftimetime24', 'langconfig');
113-
}
114-
115-
return userdate($time, empty($timeformat) ? $langtimeformat : $timeformat);
102+
$humantime = new humandate(
103+
timestamp: $time,
104+
near: null,
105+
timeonly: true
106+
);
107+
return $OUTPUT->render($humantime);
116108
}
117109

118110
/**
@@ -136,82 +128,14 @@ function calendar_time_representation($time) {
136128
function calendar_format_event_time($event, $now, $linkparams = null, $usecommonwords = true, $showtime = 0) {
137129
\core\deprecation::emit_deprecation_if_present(__FUNCTION__);
138130

139-
$starttime = $event->timestart;
140-
$endtime = $event->timestart + $event->timeduration;
131+
global $OUTPUT;
141132

142-
if (empty($linkparams) || !is_array($linkparams)) {
143-
$linkparams = [];
144-
}
133+
$humanperiod = new humantimeperiod(
134+
starttimestamp: $event->timestart,
135+
endtimestamp: $event->timestart + $event->timeduration,
136+
link: new \moodle_url(CALENDAR_URL . 'view.php'),
137+
);
145138

146-
$linkparams['view'] = 'day';
147-
148-
// OK, now to get a meaningful display.
149-
// Check if there is a duration for this event.
150-
if ($event->timeduration) {
151-
// Get the midnight of the day the event will start.
152-
$usermidnightstart = usergetmidnight($starttime);
153-
// Get the midnight of the day the event will end.
154-
$usermidnightend = usergetmidnight($endtime);
155-
// Check if we will still be on the same day.
156-
if ($usermidnightstart == $usermidnightend) {
157-
// Check if we are running all day.
158-
if ($event->timeduration == DAYSECS) {
159-
$time = get_string('allday', 'calendar');
160-
} else { // Specify the time we will be running this from.
161-
$datestart = calendar_time_representation($starttime);
162-
$dateend = calendar_time_representation($endtime);
163-
$time = $datestart . ' <strong>&raquo;</strong> ' . $dateend;
164-
}
165-
166-
// Set printable representation.
167-
if (!$showtime) {
168-
$day = calendar_day_representation($event->timestart, $now, $usecommonwords);
169-
$url = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', $linkparams), 0, 0, 0, $endtime);
170-
$eventtime = \html_writer::link($url, $day) . ', ' . $time;
171-
} else {
172-
$eventtime = $time;
173-
}
174-
} else { // It must spans two or more days.
175-
$daystart = calendar_day_representation($event->timestart, $now, $usecommonwords) . ', ';
176-
if ($showtime == $usermidnightstart) {
177-
$daystart = '';
178-
}
179-
$timestart = calendar_time_representation($event->timestart);
180-
$dayend = calendar_day_representation($event->timestart + $event->timeduration, $now, $usecommonwords) . ', ';
181-
if ($showtime == $usermidnightend) {
182-
$dayend = '';
183-
}
184-
$timeend = calendar_time_representation($event->timestart + $event->timeduration);
185-
186-
// Set printable representation.
187-
if ($now >= $usermidnightstart && $now < strtotime('+1 day', $usermidnightstart)) {
188-
$url = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', $linkparams), 0, 0, 0, $endtime);
189-
$eventtime = $timestart . ' <strong>&raquo;</strong> ' . \html_writer::link($url, $dayend) . $timeend;
190-
} else {
191-
// The event is in the future, print start and end links.
192-
$url = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', $linkparams), 0, 0, 0, $starttime);
193-
$eventtime = \html_writer::link($url, $daystart) . $timestart . ' <strong>&raquo;</strong> ';
194-
195-
$url = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', $linkparams), 0, 0, 0, $endtime);
196-
$eventtime .= \html_writer::link($url, $dayend) . $timeend;
197-
}
198-
}
199-
} else { // There is no time duration.
200-
$time = calendar_time_representation($event->timestart);
201-
// Set printable representation.
202-
if (!$showtime) {
203-
$day = calendar_day_representation($event->timestart, $now, $usecommonwords);
204-
$url = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', $linkparams), 0, 0, 0, $starttime);
205-
$eventtime = \html_writer::link($url, $day) . ', ' . trim($time);
206-
} else {
207-
$eventtime = $time;
208-
}
209-
}
210-
211-
// Check if It has expired.
212-
if ($event->timestart + $event->timeduration < $now) {
213-
$eventtime = '<span class="dimmed_text">' . str_replace(' href=', ' class="dimmed" href=', $eventtime) . '</span>';
214-
}
139+
return $OUTPUT->render($humanperiod);
215140

216-
return $eventtime;
217141
}

0 commit comments

Comments
 (0)