Created
March 27, 2014 13:50
-
-
Save LightSystem/9808003 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
/** | |
* | |
* Implements the standard calculation for the final age | |
* | |
* @param birthDate | |
* @param contractBeginDate | |
* @return the technical age | |
* @throws InvalidBirthDateException | |
*/ | |
private int calculateFinalAge(Calendar birthDate, Calendar contractBeginDate) throws InvalidBirthDateException{ | |
int birthYear = birthDate.get(Calendar.YEAR); | |
int birthMonth = birthDate.get(Calendar.MONTH); | |
int contractBeginYear = contractBeginDate.get(Calendar.YEAR); | |
int contractBeginMonth = contractBeginDate.get(Calendar.MONTH); | |
int tecAge; | |
if(birthDate.after(contractBeginDate)){ | |
throw new InvalidBirthDateException("birthDate cannot be defined as being after the supplied contractBeginDate"); | |
} else { | |
int yearDif = contractBeginYear - birthYear; | |
int monthDif = contractBeginMonth - birthMonth; | |
if(monthDif < 0){ | |
monthDif += 12; | |
yearDif -= 1; | |
} | |
if(monthDif > 6){ | |
yearDif += 1; | |
} | |
tecAge = yearDif; | |
return tecAge; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment