Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Unified Diff: webrtc/base/timeutils.cc

Issue 1468273004: Provide method for returning certificate expiration timestamp. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Address hbos' feedback comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« webrtc/base/sslidentity_unittest.cc ('K') | « webrtc/base/timeutils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« webrtc/base/sslidentity_unittest.cc ('K') | « webrtc/base/timeutils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698