Skip to content

Instantly share code, notes, and snippets.

@riaf
Created March 10, 2011 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riaf/863507 to your computer and use it in GitHub Desktop.
Save riaf/863507 to your computer and use it in GitHub Desktop.
カレンダーっぽい感じのあれ
<?php
function getCalendar($date) {
if ($date instanceof DateTime === false) {
$date = new DateTime($date);
}
$sdate = clone $date;
$sdate->modify('first day of');
$edate = clone $sdate;
$edate->modify('+1 month');
if ($sdate->format('w')) {
$sdate->modify('last sunday');
}
if ($edate->format('w')) {
$edate->modify('next sunday');
}
$period = new DatePeriod(
$sdate,
new DateInterval('P1D'),
$edate
);
return $period;
}
foreach (getCalendar(new DateTime('+1 month')) as $k => $d) {
if ($k !== 0 && $k % 7 === 0) {
echo PHP_EOL;
}
echo $d->format("\td");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment