diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/time_zone.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/common/time_zone.cpp b/src/common/time_zone.cpp index a25f8b040..1ee63bf80 100644 --- a/src/common/time_zone.cpp +++ b/src/common/time_zone.cpp | |||
| @@ -35,11 +35,13 @@ std::string GetDefaultTimeZone() { | |||
| 35 | 35 | ||
| 36 | // Results are not comparable to seconds since Epoch | 36 | // Results are not comparable to seconds since Epoch |
| 37 | static std::time_t TmSpecToSeconds(const struct std::tm& spec) { | 37 | static std::time_t TmSpecToSeconds(const struct std::tm& spec) { |
| 38 | const int year = spec.tm_year - 1; // Years up to now | ||
| 39 | const int leap_years = year / 4 - year / 100; | ||
| 38 | std::time_t cumulative = spec.tm_year; | 40 | std::time_t cumulative = spec.tm_year; |
| 39 | cumulative = cumulative * 365 + spec.tm_yday; // Years to days | 41 | cumulative = cumulative * 365 + leap_years + spec.tm_yday; // Years to days |
| 40 | cumulative = cumulative * 24 + spec.tm_hour; // Days to hours | 42 | cumulative = cumulative * 24 + spec.tm_hour; // Days to hours |
| 41 | cumulative = cumulative * 60 + spec.tm_min; // Hours to minutes | 43 | cumulative = cumulative * 60 + spec.tm_min; // Hours to minutes |
| 42 | cumulative = cumulative * 60 + spec.tm_sec; // Minutes to seconds | 44 | cumulative = cumulative * 60 + spec.tm_sec; // Minutes to seconds |
| 43 | return cumulative; | 45 | return cumulative; |
| 44 | } | 46 | } |
| 45 | 47 | ||