Created
July 26, 2008 10:33
-
-
Save jiphex/2631 to your computer and use it in GitHub Desktop.
Week calculator for Lancaster University
This file contains hidden or 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 | |
// The year start date... | |
define("YEARSTART", mktime(0, 0, 0, 10, 5, 2007), FALSE); | |
// Calculates the week number from the start of the year as set in the | |
// general configuration files. Returns an array containing the uni week | |
// number [0], the term name as a string [1] and a boolean if the current | |
// week is during a holiday [2]... | |
function universityWeek() { | |
// Work out this week's 'real' number... | |
$todayTimestamp = mktime(0, 0, 0, date("n"), date("j"), date("Y")); | |
$realWeek = ceil(($todayTimestamp - YEARSTART) / 604800); | |
// And from that work out the university week and holiday flag... | |
if ($realWeek == 0) { | |
$university = array(0, FALSE); | |
} else if (($realWeek > 0) && ($realWeek <= 10)) { | |
$university = array($realWeek, "Michaelmas Term", FALSE); | |
} else if (($realWeek > 10) && ($realWeek <= 14)) { | |
$university = array(10, "Michaelmas Term", TRUE); | |
} else if (($realWeek > 14) && ($realWeek <= 24)) { | |
$university = array(($realWeek - 4), "Lent Term", FALSE); | |
} else if (($realWeek > 24) && ($realWeek < 28)) { | |
$university = array(20, "Lent Term", TRUE); | |
} else if (($realWeek >= 29) && ($realWeek <= 39)) { | |
$university = array(($realWeek - 8), "Summer Term", FALSE); | |
} else { | |
$university = array(-1, "Summer Vacation", TRUE); | |
} | |
print "<!--DEBUG-realweek=$realWeek-->\n"; | |
return $university; | |
} | |
$week = universityWeek(); | |
?> | |
<style type='text/css'> | |
body { | |
text-align: center; | |
margin-top: 10%; | |
font-family: sans-serif; | |
} | |
#preface { | |
font-size:12pt; | |
color: #676767; | |
} | |
</style> | |
<h1 id='preface'> | |
At Lancaster University... | |
</h1> | |
<? if($week[2] == 1) { | |
?> | |
<h1 class='week'>It's a Holiday!</h1> | |
<? | |
} else { | |
?> | |
<h1 class='week'>It's Week <span style='font-size: 100pt'><?=$week[0]?>< /span> of <?=$week[1]?>. | |
<? | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment