Last active
December 25, 2015 14:29
-
-
Save Veedrac/6990903 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
fun normalizeDate (d1::d2::nil) = (if d1 < 5 then d1 + 10 else d1) * 10 + d2 | |
| normalizeDate _ = raise Match; | |
exception DateOutOfBounds | |
fun denormalizeDate date_number = | |
if | |
date_number < 50 orelse date_number > 149 | |
then | |
raise DateOutOfBounds | |
else let | |
val decades = (date_number div 10) | |
val years = (date_number mod 10) | |
in | |
[decades mod 10, years] | |
end; | |
fun compareDates date1 date2 = normalizeDate date1 > normalizeDate date2; | |
fun subtractYears num_years date = denormalizeDate ((normalizeDate date) - num_years); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment