Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 274... Línea 274...
274
    }
274
    }
Línea 275... Línea 275...
275
 
275
 
276
    /**
276
    /**
277
     * Returns a formatted string that represents a date in user time.
277
     * Returns a formatted string that represents a date in user time.
278
     *
-
 
279
     * Returns a formatted string that represents a date in user time
-
 
280
     * <b>WARNING: note that the format is for strftime(), not date().</b>
-
 
281
     * Because of a bug in most Windows time libraries, we can't use
-
 
282
     * the nicer %e, so we have to use %d which has leading zeroes.
-
 
283
     * A lot of the fuss in the function is just getting rid of these leading
-
 
284
     * zeroes as efficiently as possible.
-
 
285
     *
278
     *
286
     * If parameter fixday = true (default), then take off leading
279
     * If parameter fixday = true (default), then take off leading
287
     * zero from %d, else maintain it.
280
     * zero from %d, else maintain it.
288
     *
281
     *
289
     * @param int $time the timestamp in UTC, as obtained from the database
282
     * @param int $time the timestamp in UTC, as obtained from the database
Línea 301... Línea 294...
301
 
294
 
302
        if (empty($format)) {
295
        if (empty($format)) {
303
            $format = get_string('strftimedaydatetime', 'langconfig');
296
            $format = get_string('strftimedaydatetime', 'langconfig');
Línea -... Línea 297...
-
 
297
        }
-
 
298
 
-
 
299
        // Note: This historical logic was about fixing 12-hour time to remove
-
 
300
        // unnecessary leading zero was required because on Windows, PHP strftime
-
 
301
        // function did not support the correct 'hour without leading zero' parameter (%l).
-
 
302
        // This is no longer required because we use IntlDateFormatter.
-
 
303
        // Unfortunately though the original implementation was done incorrectly.
-
 
304
        // The documentation for strftime notes that for the "%l" and "%e" specifiers where
-
 
305
        // no leading zero is used, a space is used instead.
-
 
306
        // As a result we switch to the new format specifiers "%l" and "%e", wrap them in placeholders
304
        }
307
        // and then remove the spaces.
-
 
308
 
305
 
309
        if (empty($CFG->nofixday) && $fixday) {
-
 
310
            // Config.php can force %d not to be fixed, but only if the format did not specify it.
-
 
311
            $format = str_replace(
306
        if (!empty($CFG->nofixday)) { // Config.php can force %d not to be fixed.
312
                '%d',
-
 
313
                'DDHH%eHHDD',
-
 
314
                $format,
-
 
315
            );
-
 
316
        }
307
            $fixday = false;
317
 
-
 
318
        if (empty($CFG->nofixhour) && $fixhour) {
-
 
319
            $format = str_replace(
308
        } else if ($fixday) {
320
                '%I',
-
 
321
                'DDHH%lHHDD',
-
 
322
                $format,
-
 
323
            );
-
 
324
        }
-
 
325
 
-
 
326
        if (is_string($time) && !is_numeric($time)) {
-
 
327
            debugging(
-
 
328
                "Invalid time passed to timestamp_to_date_string: '{$time}'",
309
            $formatnoday = str_replace('%d', 'DD', $format);
329
                DEBUG_DEVELOPER,
310
            $fixday = ($formatnoday != $format);
330
            );
Línea 311... Línea -...
311
            $format = $formatnoday;
-
 
312
        }
-
 
313
 
-
 
314
        // Note: This logic about fixing 12-hour time to remove unnecessary leading
331
            $time = 0;
315
        // zero is required because on Windows, PHP strftime function does not
-
 
316
        // support the correct 'hour without leading zero' parameter (%l).
332
        }
317
        if (!empty($CFG->nofixhour)) {
-
 
318
            // Config.php can force %I not to be fixed.
-
 
319
            $fixhour = false;
-
 
320
        } else if ($fixhour) {
-
 
321
            $formatnohour = str_replace('%I', 'HH', $format);
333
 
Línea 322... Línea -...
322
            $fixhour = ($formatnohour != $format);
-
 
323
            $format = $formatnohour;
334
        if ($time === null || $time === '') {
Línea 324... Línea 335...
324
        }
335
            $time = 0;
Línea 325... Línea -...
325
 
-
 
326
        $time = (int)$time; // Moodle allows rubbish in input...
-
 
327
        $datestring = date_format_string($time, $format, $timezone);
336
        }
328
 
337
 
329
        date_default_timezone_set(\core_date::get_user_timezone($timezone));
338
        $time = new \DateTime("@{$time}", new \DateTimeZone(date_default_timezone_get()));
330
 
-
 
331
        if ($fixday) {
339
 
332
            $daystring  = ltrim(str_replace(array(' 0', ' '), '', date(' d', $time)));
340
        date_default_timezone_set(\core_date::get_user_timezone($timezone));
Línea 333... Línea 341...
333
            $datestring = str_replace('DD', $daystring, $datestring);
341
 
Línea -... Línea 342...
-
 
342
        $formattedtime = \core_date::strftime(
-
 
343
            $format,
-
 
344
            $time,
-
 
345
            get_string('locale', 'langconfig'),
334
        }
346
        );
335
        if ($fixhour) {
347
 
Línea 336... Línea 348...
336
            $hourstring = ltrim(str_replace(array(' 0', ' '), '', date(' h', $time)));
348
        \core_date::set_default_server_timezone();
337
            $datestring = str_replace('HH', $hourstring, $datestring);
349
 
338
        }
350
        // Use a simple regex to remove the placeholders and any leading spaces to match the historically