Created
April 17, 2009 17:33
-
-
Save Jonty/97149 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 | |
function getMiddleDay($day, $month, $year) { | |
$thisMonth = mktime(0, 0, 0, $month, 0, $year); | |
$daysInMonth = date('t', $thisMonth); | |
$middleTimestamp = mktime(0, 0, 0, $month, floor($daysInMonth/2), $year); | |
$potentials = array(); | |
foreach (array(2,3) as $i) { | |
$timestamp = strtotime("{$i} {$day}", $thisMonth); | |
$potentials[abs($timestamp - $middleTimestamp)] = $timestamp; | |
} | |
ksort($potentials); | |
return array_shift($potentials); | |
} | |
$timestamp = getMiddleDay('thursday', date('n'), date('Y')); | |
if (time() > strtotime('10pm', $timestamp)) { | |
$nextMonth = strtotime('next month'); | |
$timestamp = getMiddleDay( | |
'thursday', | |
date('n', $nextMonth), | |
date('Y', $nextMonth) | |
); | |
} | |
// Next event | |
print date('d-m-Y',$timestamp)."\n"; | |
// Time remaining | |
$startTime = strtotime('7pm', $timestamp); | |
$remaining = $startTime - time(); | |
if ($remaining <= 0) { | |
print "Currently in progress!\n"; | |
} else { | |
$days = floor($remaining / 86400); | |
$remaining -= $days * 86400; | |
$hours = floor($remaining / 3600); | |
$remaining -= $hours * 3600; | |
$minutes = ceil($remaining / 60); | |
print "{$days} days, {$hours} hour(s), {$minutes} minutes until beer.\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment