24
24
25
25
defined ('MOODLE_INTERNAL ' ) || die ();
26
26
27
+ use core_calendar \output \humandate ;
28
+ use core_calendar \output \humantimeperiod ;
29
+
27
30
/**
28
31
* Return the representation day.
29
32
*
@@ -92,27 +95,16 @@ function calendar_day_representation($tstamp, $now = false, $usecommonwords = tr
92
95
mdl: 'MDL-83873 ' ,
93
96
)]
94
97
function calendar_time_representation ($ time ) {
95
- static $ langtimeformat = null ;
96
-
97
98
\core \deprecation::emit_deprecation_if_present (__FUNCTION__ );
98
99
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 ;
107
101
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 );
116
108
}
117
109
118
110
/**
@@ -136,82 +128,14 @@ function calendar_time_representation($time) {
136
128
function calendar_format_event_time ($ event , $ now , $ linkparams = null , $ usecommonwords = true , $ showtime = 0 ) {
137
129
\core \deprecation::emit_deprecation_if_present (__FUNCTION__ );
138
130
139
- $ starttime = $ event ->timestart ;
140
- $ endtime = $ event ->timestart + $ event ->timeduration ;
131
+ global $ OUTPUT ;
141
132
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
+ );
145
138
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>»</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>»</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>»</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 );
215
140
216
- return $ eventtime ;
217
141
}
0 commit comments