From 377168c4b4cd85daba6ac13c4ea69455b899ecf9 Mon Sep 17 00:00:00 2001 From: hap Date: Sun, 20 Sep 2015 17:51:30 +0200 Subject: Simplified coreutil.c gregorian_days_in_month. [William Krick] --- src/lib/util/coreutil.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/lib/util/coreutil.c') 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 +} -- cgit v1.2.3