Index: webrtc/base/timeutils.cc |
diff --git a/webrtc/base/timeutils.cc b/webrtc/base/timeutils.cc |
index fac5b66c7e005756d3c405db60752201ff27602f..16fbbe2c6f1c54b6bb8fb5c8512c1ace793c6494 100644 |
--- a/webrtc/base/timeutils.cc |
+++ b/webrtc/base/timeutils.cc |
@@ -204,4 +204,34 @@ int64_t TimestampWrapAroundHandler::Unwrap(uint32_t ts) { |
return unwrapped_ts; |
} |
+int64_t TmToSeconds(const std::tm& tm) { |
+ static short int cumul_days[12] = {0, 31, 59, 90, 120, 151, |
+ 181, 212, 243, 273, 304, 334}; |
+ |
+ int year = tm.tm_year + 1900; |
+ int month = tm.tm_mon; |
+ int day = tm.tm_mday - 1; // Make 0-based like the rest. |
+ int hour = tm.tm_hour; |
+ int min = tm.tm_min; |
+ int sec = tm.tm_sec; |
+ |
+ day += cumul_days[month]; |
nisse-webrtc
2015/11/27 12:47:12
I think you get an out-of-bounds read for invalid
torbjorng (webrtc)
2015/11/30 15:23:31
Sure, this was intended as a low-level internal fu
|
+ |
+ // Add number of leap days between 1970 and the expiration year, inclusive. |
+ day += ((year / 4 - 1970 / 4) - (year / 100 - 1970 / 100) + |
+ (year / 400 - 1970 / 400)); |
+ |
+ // If expiration time is in a leap year, number of days depends on exact date. |
+ if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) { |
+ if (month <= 2 - 1) { // February or earlier (|month| is zero based). |
+ day -= 1; |
nisse-webrtc
2015/11/27 12:47:12
This is a bit subtle... +1 for a leap year would b
torbjorng (webrtc)
2015/11/30 15:23:31
Tried to clarify.
|
+ } |
+ } |
+ |
+ // Combine all variables into seconds from 1970-01-01 00:00 (except |month| |
+ // which was accumulated into |day| above). |
+ return (((static_cast<int64_t> |
+ (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; |
+} |
+ |
} // namespace rtc |