Skip to content

Instantly share code, notes, and snippets.

@egi
Created November 4, 2011 15:32
Show Gist options
  • Save egi/1339597 to your computer and use it in GitHub Desktop.
Save egi/1339597 to your computer and use it in GitHub Desktop.
<?php
/**
* diketahui tanggal tertentu (dalam YYYY-mm-dd), keluarkan semua minggu yang
* dalam range-nya memiliki tanggal di dalam bulan berjalan. minggu dimulai dari
* hari senin.
*
* @author Agastiya S. Mohammad <[email protected]>
**/
function x(&$d, $t) { $x = $d++ % $t; return $x ?: $t; }
$date = '2012-01-10';
list($cyear, $cmonth, ) = explode('-', $date);
// ambil semua yang diperlukan
$first_ts = mktime(0, 0, 0, (int)$cmonth, 1, (int)$cyear);
list($Y, $F, $first_dow) = explode('-', date('Y-F-N', $first_ts));
$rs_start = $first_ts - 86400 * ($first_dow-1);
echo "$F $Y\n\nWeek Sn Sl Rb Km Ju Sa Mg\n";
while (true)
{
list($y, $m, $d, $t, $rs_week) = explode('-', date('Y-m-d-t-W', $rs_start));
$in_month = ($m <= $cmonth && $y == $cyear) || $y < $cyear;
if (!$in_month) exit;
printf("[%02d] %2d %2d %2d %2d %2d %2d %2d\n",
$rs_week,
x($d, $t), x($d, $t), x($d, $t), x($d, $t), x($d, $t), x($d, $t), x($d, $t));
$rs_start += 604800;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment