function date2WeekDate($y, $m, $d) { $jd = date2jd($y, $m, $d); $cz = zeller($y, $m, $d); if ($cz == 0) { $cz = 7; } if ($m == 12) { // 翌年の1/1 $w = zeller($y + 1, 1, 1); $offset = $w == 0 ? 7 : $w; // 翌年の1/1が木までの場合 // 2:火 3:水 4:木 if ($offset < 5 && $offset > 1) { // 12月の最終週は、翌年に属する可能性がある $jd_y0101 = date2jd($y + 1, 1, 1); $seq = $jd_y0101 - $jd; // 月火水までなら翌年 if ($seq < $offset) { return array($y - 1, "01", $cz); } } } $w = zeller($y, 1, 1); // $offset = 1:月 2:火 3:水 4:木 5:金 6:土 7:日 $offset = $w == 0 ? 7 : $w; $jd_y0101 = date2jd($y, 1, 1); $week = ceil(($jd - $jd_y0101 + $offset) / 7); // 1/1が 金土日の場合は、前年に属するので計算結果から1週減らす if ($offset > 4) { $week--; } // 計算したい日が結果ゼロ週の場合は、前年週を再算出 if ($week == 0) { return date2WeekDate($y - 1, 12, 31); } return array($y, str_pad($week, 2, "0", STR_PAD_LEFT), $cz); // return sprintf("%02d", $week); }
function init($y, $m, $d) { $this->y = $y; $this->m = $m; $this->d = $d; $this->w = zeller($y, $m, $d); $this->n = (int) (($d - 1) / 7) + 1; // Is it equivalent to the n-th time? $this->rc['rc'] = 0; $this->rc['name'] = ''; $this->my_name = get_class($this); }