mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-16 10:39:49 +00:00
Fixed calculation of the number of leap days
This commit is contained in:
1 parent
25863b59a6
commit
f741349d51
1 file changed
+5
-1
+5
-1
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user