Topic: date vs strftime

Hello !

punbb use the fonction date() wich not allow the use of the locals to display the date in specific language. Is it because the use of strftime is lower ? If no, is it possible to use strftime in the next version ?

2

Re: date vs strftime

You can make your own date translate function. It's not that hard. In function.php on 595 change

    $date = date($pun_config['o_date_format'], $timestamp);
    $today = date($pun_config['o_date_format'], $now+$diff);
    $yesterday = date($pun_config['o_date_format'], $now+$diff-86400);

to

    $date = ldate($pun_config['o_date_format'], $timestamp);
    $today = ldate($pun_config['o_date_format'], $now+$diff);
    $yesterday = ldate($pun_config['o_date_format'], $now+$diff-86400);

Then, add a new function to functions.php. This is for Dutch, but you can easily translate it.

function ldate($format, $timestamp = '')
{
    // same as date() function, only change names to locals
    if ($timestamp == '') 
    {
        $timestamp = time();
    }

    $date = date($format,$timestamp);
    
    // change names of the days
    $date = str_replace('Monday','maandag',$date);
    $date = str_replace('Tuesday','dinsdag',$date);
    $date = str_replace('Wednesday','woensdag',$date);
    $date = str_replace('Thursday','donderdag',$date);
    $date = str_replace('Friday','vrijdag',$date);
    $date = str_replace('Saturday','zaterdag',$date);
    $date = str_replace('Sunday','zondag',$date);
    
    // change names of the months
    $date = str_replace('January','januari',$date);
    $date = str_replace('February','februari',$date);
    $date = str_replace('March','maart',$date);
    $date = str_replace('April','april',$date);
    $date = str_replace('May','mei',$date);
    $date = str_replace('June','juni',$date);
    $date = str_replace('July','juli',$date);
    $date = str_replace('August','augustus',$date);
    $date = str_replace('September','september',$date);
    $date = str_replace('October','oktober',$date);
    $date = str_replace('November','november',$date);
    $date = str_replace('December','december',$date);
    return $date;
}

Re: date vs strftime

Why re-invent the wheel ? srftime handle all this, without need to hack PunBB or maintain the code.

Re: date vs strftime

The "problem" with strftime is that it requires the proper locale to be loaded and it hardly ever is. Even worse, setting it through PHP (via setlocale()) also very seldomly works because hosting companies generally forget to install the different locales.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: date vs strftime

by default, if locals are not installed, strftime don't give any result (in english) ?

Re: date vs strftime

The default locale is C (posix) which means English (or so I think).

"Programming is like sex: one mistake and you have to support it for the rest of your life."

7 (edited by okparanoid 2005-03-09 13:16)

Re: date vs strftime

So what's the problem ?
In all case english is available, and for specific use (different language) the user is advertise that the good local has to be installed, if not the use is like the function date...

Am i wrong ?

Re: date vs strftime

The problem right now is upgrading. People will freak out when their customized date format is reset and the old one they used doesn't work anymore.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: date vs strftime

Localization vs people don't reading documentation *and* using bad hosting ? Is this a real question ? :-)