Tools\Utility\Time::cWeekBeginning PHP Method

cWeekBeginning() public static method

Calculate the beginning of a calender week if no calendar week is given get the beginning of the first week of the year
public static cWeekBeginning ( integer $year, integer $cWeek ) : integer
$year integer (format xxxx)
$cWeek integer (optional, defaults to first, range 1...52/53)
return integer Timestamp
    public static function cWeekBeginning($year, $cWeek = 0)
    {
        if ($cWeek <= 1 || $cWeek > static::cWeeks($year)) {
            $first = mktime(0, 0, 0, 1, 1, $year);
            $wtag = date('w', $first);
            if ($wtag <= 4) {
                /* Thursday or less: back to Monday */
                $firstmonday = mktime(0, 0, 0, 1, 1 - ($wtag - 1), $year);
            } elseif ($wtag != 1) {
                /* Back to Monday */
                $firstmonday = mktime(0, 0, 0, 1, 1 + (7 - $wtag + 1), $year);
            } else {
                $firstmonday = $first;
            }
            return $firstmonday;
        }
        $monday = strtotime($year . 'W' . static::pad($cWeek) . '1');
        return $monday;
    }