Reliable strtotime() result for different languages

Posted by Maksee on Stack Overflow See other posts from Stack Overflow or by Maksee
Published on 2010-04-13T13:21:31Z Indexed on 2010/04/13 13:22 UTC
Read the original article Hit count: 270

Filed under:
|
|
|

There was always a strange bug in Joomla when adding new article with back-end displayed with a language other than English (for me it's Russian). The field "Finish Publishing" started to be current date instead of "Never" equivalent in Russian.

For a site in php4 finally found that strtotime function returns different results for arbitrary words. For "Never" it always -1 and joomla relies on this result in the JDate implementation. But in other case it sometimes returns a valid date. For russian translation of Never (???????) it is the case, but also for single "N" it is the case, so if one decided to change the string to some other he or she would face the same issue.

So the code below

    <?php
      echo "Res:".strtotime("N")."<br>";
      echo "Res:".strtotime("Nev")."<br>";
      echo "Res:".strtotime("Neve")."<br>";
      echo "Res:".strtotime("Never")."<br>";
    ?>

Outputs:

    Res:1271120400
    Res:-1
    Res:-1
    Res:-1

So what are the solutions would be in this case? I would like not to write language-specific date.php handler, but to modify date method of JDate class, but what are language-neutral changes would be in order to detect invalid string.

Thank you

© Stack Overflow or respective owner

Related posts about php

Related posts about php4