示例#1
0
 function amr_date_i18n($dateformatstring, $dateobj = null)
 {
     global $wp_locale;
     // store original value for language with untypical grammars
     // see http://core.trac.wordpress.org/ticket/9396
     $req_format = $dateformatstring;
     //$datefunc = 'date';
     if (!empty($wp_locale->month) && !empty($wp_locale->weekday)) {
         $datemonth = $wp_locale->get_month($dateobj->format('m'));
         $datemonth_abbrev = $wp_locale->get_month_abbrev($datemonth);
         $w = $dateobj->format('w');
         if ($w == '-1') {
             $w = get_oldweekdays($dateobj);
         }
         /* php seems to break around 1760 and google passed a zero year date */
         $dateweekday = $wp_locale->get_weekday($w);
         $dateweekday_abbrev = $wp_locale->get_weekday_abbrev($dateweekday);
         $datemeridiem = $wp_locale->get_meridiem($dateobj->format('a'));
         $datemeridiem_capital = $wp_locale->get_meridiem($dateobj->format('A'));
         $dateformatstring = ' ' . $dateformatstring;
         $dateformatstring = preg_replace("/([^\\\\])D/", "\\1" . backslashit($dateweekday_abbrev), $dateformatstring);
         $dateformatstring = preg_replace("/([^\\\\])F/", "\\1" . backslashit($datemonth), $dateformatstring);
         $dateformatstring = preg_replace("/([^\\\\])l/", "\\1" . backslashit($dateweekday), $dateformatstring);
         $dateformatstring = preg_replace("/([^\\\\])M/", "\\1" . backslashit($datemonth_abbrev), $dateformatstring);
         $dateformatstring = preg_replace("/([^\\\\])a/", "\\1" . backslashit($datemeridiem), $dateformatstring);
         $dateformatstring = preg_replace("/([^\\\\])A/", "\\1" . backslashit($datemeridiem_capital), $dateformatstring);
         $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring) - 1);
     }
     $j = $dateobj->format($dateformatstring);
     // allow plugins to redo this entirely for languages with untypical grammars
     $j = apply_filters('amr_date_i18n', $j, $req_format, $dateobj);
     return $j;
 }
示例#2
0
function amr_goto_byday($dateobj, $byday, $sign)
{
    global $amr_day_of_week_no;
    $dayofweek = $dateobj->format('w');
    /* 0=sunday, 6 = saturday */
    if ($dayofweek == '-1') {
        $dayofweek = get_oldweekdays($dateobj);
    }
    /* php seems to break around 1760   */
    $target = $amr_day_of_week_no[$byday];
    /*  mo=1 ,su=7  */
    $adjustment = $target - $dayofweek;
    if (isset($_GET['rdebug'])) {
        echo '<br />GO to day of week from ' . $dateobj->format('Ymd l') . ' going to ' . $sign . $byday . ' Target = ' . $target . ' Dayofweek = ' . $dayofweek . ' ' . $dateobj->format('l');
    }
    if ($sign === '+') {
        if ($adjustment < 0) {
            $adjustment = $adjustment + 7;
        }
    } else {
        // sign must be neg
        if ($adjustment > 0) {
            $adjustment = $adjustment - 7;
        }
    }
    if ($adjustment == 7) {
        $adjustment = 0;
    }
    // else will skip the first one if it matches
    if (isset($_GET['rdebug'])) {
        echo '<br />Adj = ' . $adjustment;
    }
    $d2 = new DateTime();
    // if cloning ok dont need tz
    $d2 = clone $dateobj;
    date_modify($d2, $adjustment . ' days');
    if (isset($_GET['rdebug'])) {
        echo ' Got date = ' . $d2->format('Ymd l');
    }
    return $d2;
}