About function userdate() in moodlelib.php

About function userdate() in moodlelib.php

de Zhigang Sun -
Número de respuestas: 7
The defination:

 * @uses HOURSECS
 * @param  int $date timestamp in GMT
 * @param string $format strftime format
 * @param float $timezone
 * @param boolean $fixday If true (default) then the leading
 * zero from %d is removed. If false then the leading zero is mantained.
 * @return string
 */
function userdate($date, $format='', $timezone=99, $fixday = true) {

Why do things like this? If users don't like the leading zero, they can change the 'strf*' string to "%e" instead of "%d", though "%e" has a leading space. But in the recent code, if I would like to see the leading zero, I must modify the source code.
Is there any other solution to solve this problem? Thank you!
Promedio de valoraciones: -
En respuesta a Zhigang Sun

Re: About function userdate() in moodlelib.php

de Zhigang Sun -
I just found this:
$CFG->nofixday = true;

But it seems not work. Is it a bug?

In moodle.php:
    if ($fixday and empty($CFG->nofixday)) {    // Config.php can force %d not to be fixed.
        $fixday = ($formatnoday != $format);
    }

Can this code work? If $CFG->nofixday isn't empty, $fixday will still be true.


En respuesta a Zhigang Sun

Re: About function userdate() in moodlelib.php

de Martin Dougiamas -
Imagen de Core developers Imagen de Documentation writers Imagen de Moodle HQ Imagen de Particularly helpful Moodlers Imagen de Plugin developers Imagen de Testers

Thanks, yes, that's screwy! Try this (in CVS now):

    if (!empty($CFG->nofixday)) {  // Config.php can force %d not to be fixed.
        $fixday = false;
    } else if ($fixday) {
        $formatnoday = str_replace('%d', 'DD', $format);
        $fixday = ($formatnoday != $format);
    }
En respuesta a Martin Dougiamas

Re: About function userdate() in moodlelib.php

de Zhigang Sun -
So efficient!!!

But config-dist.php says:

// This setting will cause the userdate() function not to fix %d in
// date strings, and just let them show with a zero prefix.
//      $CFG->nofixday = true;

If someone defines it to false...
My English is very poor. If I misunderstand the comments above, ignore me freely, smile
En respuesta a Zhigang Sun

Re: About function userdate() in moodlelib.php

de Martin Dougiamas -
Imagen de Core developers Imagen de Documentation writers Imagen de Moodle HQ Imagen de Particularly helpful Moodlers Imagen de Plugin developers Imagen de Testers
No, that's OK.

empty($var) is true if $var is false or doesn't exist.
En respuesta a Zhigang Sun

Re: About function userdate() in moodlelib.php

de Martin Dougiamas -
Imagen de Core developers Imagen de Documentation writers Imagen de Moodle HQ Imagen de Particularly helpful Moodlers Imagen de Plugin developers Imagen de Testers
Because %e doesn't work on Windows.