Fixed calculation of the number of leap days

This commit is contained in:
Sergey Lyubka committed 2012-09-21 17:21:04 +01:00
1 parent 25863b59a6
commit f741349d51
1 file changed
+5 -1
+5 -1
View File
@@ -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;
}