Last active
December 9, 2016 07:34
-
-
Save makoru-hikage/d7b9dd95234ac6355956c364756c5096 to your computer and use it in GitHub Desktop.
This function determines the subsequent and preceding semesters, trimesters, or quarters by month
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 | |
//With enough logic and math, one adept programmer can use this to determine what school year a semester belongs to. | |
//Using only the declared arguments of this lone user-defined function. | |
//Tested using PHP Fiddle (http://phpfiddle.org/) | |
define ('INTO_SEMESTERS', 2); | |
define ('INTO_TRIMESTERS', 4); | |
define ('INTO_QUARTERS', 3); | |
function getNsterOfYear($division, $date, $monthStart){ | |
$month = date_parse_from_format('Y-n-d', $date)['month']; | |
return ceil(( $month - (12 - $monthStart) + 1) / ( 12 / $division )); | |
} | |
echo '<br>Assume that each new cycle/year starts at 30th of June (which the the 6th month).'; | |
echo "<br>You'll see a date and a number beside it. Should you see a number less than 1,"; | |
echo '<br>assume that the Nster moved backward (Nster - 1), '; | |
echo '<br>such as 1st sem is preceded by previous 4th sem <br>'; | |
foreach ([INTO_SEMESTERS, INTO_TRIMESTERS, INTO_QUARTERS] as $Nster){ | |
echo "<br>When a year is divided into ".$Nster; | |
for($i = 1; $i <= 12; $i++){ | |
echo "<br>2013-$i-1: ".getNsterOfYear($Nster, "2013-$i-1", 6); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment