Skip to content

Instantly share code, notes, and snippets.

@murdaugh
Last active December 24, 2015 03:09
Show Gist options
  • Select an option

  • Save murdaugh/6735164 to your computer and use it in GitHub Desktop.

Select an option

Save murdaugh/6735164 to your computer and use it in GitHub Desktop.

Revisions

  1. murdaugh revised this gist Sep 27, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions custom locale function
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    function my_strftime($format,$time=null) {
    global $my_locale; //this is set in the header as either en_US or es_ES
    if($time == null) $time = time(); //if the time isn't passed in, then use the current timestamp
  2. murdaugh created this gist Sep 27, 2013.
    21 changes: 21 additions & 0 deletions custom locale function
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    function my_strftime($format,$time=null) {
    global $my_locale; //this is set in the header as either en_US or es_ES
    if($time == null) $time = time(); //if the time isn't passed in, then use the current timestamp

    if($my_locale == "en_US") return strftime($format,$time); //If it's american english, just format the time as requested
    else { //in my case, the only other option is es_ES, but this could be changed for whatever purposes you have
    global $es_locale_string;

    // we only care about day names and abbreviations and
    // month names and abbreviations, so let's turn those
    // into integers. and then get them out of the
    // es_locale_string which has been shared here:
    // https://gist.github.com/murdaugh/6734488

    $format = str_replace("%a", $es_locale_string["weekday_abbrev"][strftime("%w",$time)], $format); //day abbreviation
    $format = str_replace("%A", $es_locale_string["weekday"][strftime("%w",$time)], $format); //day name
    $format = str_replace("%b", $es_locale_string["month_abbrev"][strftime("%m",$time)-1], $format); //month abbreviation (it's 1-based index - hence the subtraction)
    $format = str_replace("%B", $es_locale_string["month"][strftime("%m",$time)-1], $format); //month abbreviation (it's 1-based index - hence the subtraction)
    return strftime($format,$time);
    }
    }