Skip to content

Instantly share code, notes, and snippets.

@vinaydotblog
Created April 25, 2016 07:36
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 vinaydotblog/28841abcd37da45b2516bfbcb0d49abe to your computer and use it in GitHub Desktop.
Save vinaydotblog/28841abcd37da45b2516bfbcb0d49abe to your computer and use it in GitHub Desktop.
<?php
$d1 = new DateTime('2016-04-12');
$d2 = new DateTime('2016-04-16');
$ar = [
['name' => 'vinay', 'date' => new DateTime('2016-04-05')],
['name' => 'vinay', 'date' => new DateTime('2016-04-12')],
['name' => 'vinay', 'date' => new DateTime('2016-04-16')],
['name' => 'vinay', 'date' => new DateTime('2016-04-25')],
];
$filled = array();
$first_day = $ar[0]['date']->format('d');
if($first_day != 1) {
$filled = getFiller(0, $first_day);
}
foreach($ar as $key => $obj) {
$filled[] = $obj;
$first = $obj;
if(isset( $ar[$key + 1] ) ) {
$next = $ar[$key + 1];
$day2 = $next['date']->format('d');
}else {
$day2 = cal_days_in_month(CAL_GREGORIAN, 4, 2016) + 1;
}
$day1 = $first['date']->format('d');
$filled = array_merge($filled, getFiller($day1, $day2));
}
function getFiller($day1, $day2){
$filler = range($day1 + 1, $day2 - 1);
$filler = array_map(function($day){ return ['date' => (new DateTime())->setTimestamp(mktime(0,0,0, 4, $day, 2016 ))]; }, $filler);
return $filler;
}
pr($filled);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment