diff options
author | 2015-09-20 17:51:30 +0200 | |
---|---|---|
committer | 2015-09-20 17:52:47 +0200 | |
commit | 377168c4b4cd85daba6ac13c4ea69455b899ecf9 (patch) | |
tree | a1bbf6804010facdf8061f24f41c4c2aeb3f4636 | |
parent | 0bb208ce12059a112308d682c4691cc4db6c79b0 (diff) |
Simplified coreutil.c gregorian_days_in_month. [William Krick]
-rw-r--r-- | src/lib/util/coreutil.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/lib/util/coreutil.c b/src/lib/util/coreutil.c index eb7d2a92d89..87df296dd56 100644 --- a/src/lib/util/coreutil.c +++ b/src/lib/util/coreutil.c @@ -82,12 +82,11 @@ int gregorian_is_leap_year(int year) int gregorian_days_in_month(int month, int year) { - if (month == 2) - return gregorian_is_leap_year(year) ? 29 : 28; - else if (month == 4 || month == 6 || month == 9 || month == 11) - return 30; - else - return 31; + assert(month >= 1 && month <= 12) + + int days[] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; + days[1] += gregorian_is_leap_year(year) ? 1 : 0; + return days[month-1]; } @@ -121,4 +120,4 @@ void rand_memory(void *memory, size_t length) UINT32 core_crc32(UINT32 crc, const UINT8 *buf, UINT32 len) { return crc32(crc, buf, len); -}
\ No newline at end of file +} |