我正在为我的某个项目使用日历渲染库(simplecalender / donatj),但我无法弄清楚如何仅显示当月的剩余天数,而不是整月。
据我了解,这是构建日历的部分:
public function show( $echo = true ) {
if( $this->wday_names ) {
$wdays = $this->wday_names;
} else {
$today = (86400 * (date("N")));
$wdays = array();
for( $i = 0; $i < 7; $i++ ) {
$wdays[] = strftime('%a', time() - $today + ($i * 86400));
}
}
$this->arrayRotate($wdays, $this->offset);
$wday = date('N', mktime(0, 0, 1, $this->now['mon'], 1, $this->now['year'])) - $this->offset;
$no_days = cal_days_in_month(CAL_GREGORIAN, $this->now['mon'], $this->now['year']);
如果我将no_days更改为25,则日历中仅显示1-25天。所以几乎是我想要的。
知道如何才能显示25到31(7月剩下的天数)?
感谢。
以下是代码的其余部分:
$out = '<table cellpadding="0" cellspacing="0" class="SimpleCalendar"><thead><tr>';
for( $i = 0; $i < 7; $i++ ) {
$out .= '<th>' . $wdays[$i] . '</th>';
}
$out .= "</tr></thead>\n<tbody>\n<tr>";
$wday = ($wday + 7) % 7;
if( $wday == 7 ) {
$wday = 0;
} else {
$out .= str_repeat('<td class="SCprefix"> </td>', $wday);
}
$count = $wday + 1;
for( $i = 1; $i <= $no_days; $i++ ) {
$out .= '<td' . ($i == $this->now['mday'] && $this->now['mon'] == date('n') && $this->now['year'] == date('Y') ? ' class="today"' : '') . '>';
$datetime = mktime(0, 0, 1, $this->now['mon'], $i, $this->now['year']);
$out .= '<time datetime="' . date('Y-m-d', $datetime) . '">' . $i . '</time>';
$dHtml_arr = false;
if( isset($this->dailyHtml[$this->now['year']][$this->now['mon']][$i]) ) {
$dHtml_arr = $this->dailyHtml[$this->now['year']][$this->now['mon']][$i];
}
if( is_array($dHtml_arr) ) {
foreach( $dHtml_arr as $dHtml ) {
$out .= '<div class="event">' . $dHtml . '</div>';
}
}
$out .= "</td>";
if( $count > 6 ) {
$out .= "</tr>\n" . ($i != $count ? '<tr>' : '');
$count = 0;
}
$count++;
}
$out .= ($count != 1 ? str_repeat('<td class="SCsuffix"> </td>', 8 - $count) : '') . "</tr>\n</tbody></table>\n";
if( $echo ) {
echo $out;
}
return $out;
}
private function arrayRotate( &$data, $steps ) {
$count = count($data);
if( $steps < 0 ) {
$steps = $count + $steps;
}
$steps = $steps % $count;
for( $i = 0; $i < $steps; $i++ ) {
array_push($data, array_shift($data));
}
}