From f741349d5198e45bf0544eb6e8f41cdb84052e88 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Fri, 21 Sep 2012 17:21:04 +0100 Subject: [PATCH] Fixed calculation of the number of leap days --- mongoose.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mongoose.c b/mongoose.c index 71aaeccb..d6dc2905 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1742,6 +1742,10 @@ static int get_month_index(const char *s) { return -1; } +static int num_leap_years(int year) { + return year / 4 - year / 100 + year / 400; +} + // Parse UTC date-time string, and return the corresponding time_t value. static time_t parse_date_string(const char *datetime) { static const unsigned short days_before_month[] = { @@ -1761,8 +1765,8 @@ static time_t parse_date_string(const char *datetime) { &day, month_str, &year, &hour, &minute, &second) == 6)) && year > 1970 && (month = get_month_index(month_str)) != -1) { + leap_days = num_leap_years(year) - num_leap_years(1970); year -= 1970; - leap_days = year / 4 - year / 100 + year / 400; days = year * 365 + days_before_month[month] + (day - 1) + leap_days; result = days * 24 * 3600 + hour * 3600 + minute * 60 + second; }