Skip to content

Instantly share code, notes, and snippets.

@makoru-hikage
Last active December 9, 2016 07:34
Show Gist options
  • Save makoru-hikage/d7b9dd95234ac6355956c364756c5096 to your computer and use it in GitHub Desktop.
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
<?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