Created
January 4, 2016 19:13
-
-
Save eburhan/692c280b1666aa76c25c to your computer and use it in GitHub Desktop.
Herhangi bir yılın Herhangi bir ayının günlerini, haftalara bölünmüş halde takvim olarak geri döndürür.
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 | |
/** | |
* Herhangi bir yılın herhangi bir ayına ait günlerini, | |
* haftalara bölünmüş halde takvim olarak geri döndürür. | |
* 2016 Erhan BURHAN | |
*/ | |
class Calendar { | |
/** | |
* takvimi oluşturur | |
* | |
* @param integer $year | |
* @param integer $month | |
* @param string $format | |
* @return array | |
*/ | |
public static function generate($year, $month, $format = '%02d.%02d.%d') | |
{ | |
// yıla ait ayın içerisinde kaç gün var? | |
$dayCountInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year); | |
// ayın ilk günü | |
$firstDayOfMonth = sprintf('01.%02d.%d', $month, $year); | |
// ayın 1. günü, haftanın kaçıncı gününde başlıyor? | |
$weekOfFirstDay = date('w', strtotime($firstDayOfMonth)); | |
$calendar = array(); | |
for ($i = 1; $i <= $dayCountInMonth; ++$i) { | |
$dateText = sprintf($format, $i, $month, $year); | |
$dayOfWeek = date('w', strtotime($dateText)); | |
$weekOfMonth = floor(($weekOfFirstDay + $i - 2) / 7) + 1; | |
$calendar[$weekOfMonth][$dayOfWeek] = $dateText; | |
} | |
return $calendar; | |
} | |
}//Calendar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment