/**
 * @intellisense
 * @param {array} time - array(year, month, day, hour, minute, second)
 * @param {int} firstdayofweek - the first day of the week. 0 - monday, 6 - sunday, -1 - use system settings
 */
function getweekstart($time, $firstdayofweek = -1)
{
    global $locale_info;
    if ($firstdayofweek < 0) {
        $firstdayofweek = $locale_info["LOCALE_IFIRSTDAYOFWEEK"];
    }
    $wday = getdayofweek($time);
    if ($wday >= $firstdayofweek + 1) {
        $diff = $wday - $firstdayofweek - 1;
    } else {
        $diff = $wday + 7 - $firstdayofweek - 1;
    }
    return adddays($time, -$diff);
}
Esempio n. 2
0
function cached_getdayofweek($strtime)
{
    global $cache_getdayofweek;
    if (!isset($cache_getdayofweek[$strtime])) {
        $date = cached_db2time($strtime);
        $res = getdayofweek($date);
        $cache_getdayofweek[$strtime] = $res;
        return $res;
    } else {
        return $cache_getdayofweek[$strtime];
    }
}
Esempio n. 3
0
function getweekstart($time)
{
    global $locale_info;
    $wday = getdayofweek($time);
    if ($wday >= $locale_info["LOCALE_IFIRSTDAYOFWEEK"] + 1) {
        $diff = $wday - $locale_info["LOCALE_IFIRSTDAYOFWEEK"] - 1;
    } else {
        $diff = $wday + 7 - $locale_info["LOCALE_IFIRSTDAYOFWEEK"] - 1;
    }
    return adddays($time, -$diff);
}
Esempio n. 4
0
 protected function getDatesByWeek($week, $year)
 {
     global $locale_info;
     $startweekday = 0;
     if ($locale_info["LOCALE_IFIRSTDAYOFWEEK"] > 0) {
         $startweekday = 7 - $locale_info["LOCALE_IFIRSTDAYOFWEEK"];
     }
     $L = isleapyear($year) ? 1 : 0;
     $months = array(31, 28 + $L, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
     $total_days = ($week - 1) * 7;
     $i = 0;
     $sum = 0;
     while ($sum <= $total_days) {
         $sum += $months[$i++];
     }
     $sum -= $months[$i - 1];
     $month = $i;
     $day = $total_days - $sum;
     $day_of_week = getdayofweek(array($year, $month, $day));
     if ($day_of_week == 0) {
         $day_of_week = 7;
     }
     $day = $day - ($day_of_week - 1) - $startweekday;
     $dates = array();
     $dates[0] = getYMDdate(mktime(0, 0, 0, $month, $day, $year));
     $dates[1] = getYMDdate(mktime(1, 1, 1, $month, $day + 6, $year));
     return $dates;
 }