Skip to content

Instantly share code, notes, and snippets.

@Ahrengot
Created March 30, 2013 11:44
Show Gist options
  • Save Ahrengot/5276418 to your computer and use it in GitHub Desktop.
Save Ahrengot/5276418 to your computer and use it in GitHub Desktop.
Takes a UNIX timestamp and returns a string with values like "next_six_months". The returned string can contain multiple (space dilimited) values like "next_weekend next_month next_six_months"
/*-----------------------------------------------------------------------------------*/
/* FIGURE OUT WHEN CONCERTS PLAY
/*-----------------------------------------------------------------------------------*/
function get_concert_timeframe($timestamp) {
// Time filter (next weekend, 30 days, next year etc.)
$time = '';
$next_monday = strtotime("next Monday");
$weekend_start = strtotime("next Friday");
$next_month = strtotime("+1 month")2;
$next_six_months = strtotime("+6 months");
// Check if today is a weekend-day. If it is, then change $weekend_start to today.
// Minus any time that has passed today. Ie. count from the beginning of today.
$today = date('D', strtotime('now'));
if ($today == 'Fri' OR $today == 'Sat' OR $today == 'Sun') $weekend_start = strtotime('today');
if ($timestamp < strtotime('tomorrow 00:00') AND $timestamp >= strtotime('today 00:00')) $time.= 'today ';
if ($timestamp < $next_monday AND $timestamp >= $weekend_start) $time .= 'next_weekend ';
if ($timestamp < $next_month) $time .= 'next_month ';
if ($timestamp < $next_six_months) $time .= ' next_six_months';
// Reset string if concert already played, but wasn't deleted yet
if (strtotime("-1 day") > $timestamp) $time = 'already_played';
return $time;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment