Created
May 5, 2014 19:05
-
-
Save anonymous/998daa3b3c150dad2915 to your computer and use it in GitHub Desktop.
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
| type | |
| TDayRange = range[1..31] | |
| TMonthRange = range[1..12] | |
| TDate* = object | |
| year: int | |
| month: TMonthRange | |
| day: TDayRange | |
| const | |
| DaysInMonth: array[TMonthRange, TDayRange] = | |
| [TDayRange(31), 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
| proc IsLeap (year: int): bool = | |
| year mod 4 == 0 and (year mod 100 != 0 or year mod 400 == 0) | |
| proc newDate(year: int, month: TMonthRange, day: TDayRange): TDate = | |
| var | |
| m = month | |
| d = day | |
| daysInM = DaysInMonth[m] | |
| if d > daysInM: | |
| m += 1 | |
| d -= daysInM | |
| return TDate(year, m, d) | |
| echo repr(newDate(2014,5,5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment