Created
November 4, 2011 15:32
-
-
Save egi/1339597 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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