About function userdate() in moodlelib.php

About function userdate() in moodlelib.php

by Zhigang Sun -
Number of replies: 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!
Average of ratings: -
In reply to Zhigang Sun

Re: About function userdate() in moodlelib.php

by 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.


In reply to Zhigang Sun

Re: About function userdate() in moodlelib.php

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of 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);
    }
In reply to Martin Dougiamas

Re: About function userdate() in moodlelib.php

by 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
In reply to Zhigang Sun

Re: About function userdate() in moodlelib.php

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

empty($var) is true if $var is false or doesn't exist.
In reply to Martin Dougiamas

Re: About function userdate() in moodlelib.php

by Zhigang Sun -
I'm so sorry to waste your time!
I should read the php doc first...angry