Skip to content

Instantly share code, notes, and snippets.

@Langmans
Created January 25, 2016 10:26
Show Gist options
  • Save Langmans/31a52adf14b872ea9550 to your computer and use it in GitHub Desktop.
Save Langmans/31a52adf14b872ea9550 to your computer and use it in GitHub Desktop.
<?php
/**
* @param DateTime $dob
* @param string|DateTime $end
*
* @return DatePeriod
*/
function getBirthdays(DateTime $dob, $end = 'today 23:59:59')
{
if (!$end instanceof DateTime) {
$end = new DateTime($end);
}
return new DatePeriod($dob, new DateInterval('P1Y'), $end);
}
/**
* @param DateTime $dob
* @param string|DateTime $end
*
* @return mixed
*/
function getLastBirthday(DateTime $dob, $end = 'today 23:59:59')
{
/** @var DateTime[] $birthdays */
$birthdays = iterator_to_array(getBirthdays($dob, $end));
return array_pop($birthdays);
}
$last_week = new DateTime('-7 days 00:00');
if (!empty($cur_user['last_showed'])) {
$last_showed = new DateTime($cur_user['last_showed']);
} else {
$last_showed = new DateTime('1970-01-01');
}
$last_birthday = getLastBirthday(new DateTime($cur_user['dob']));
$had_birthday = $last_birthday > $last_week;
$show_movie = $last_showed < $last_week;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment