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

Unified Diff: base/time/time_win.cc

Issue 1988663002: Add: check exploded time is properly converted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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
« base/time/time_posix.cc ('K') | « base/time/time_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time_win.cc
diff --git a/base/time/time_win.cc b/base/time/time_win.cc
index ac3197a0c709140addd9145252789525a96e72e2..9fb12281384036ef919cbebe445e59de2c85ca4d 100644
--- a/base/time/time_win.cc
+++ b/base/time/time_win.cc
@@ -266,6 +266,41 @@ Time Time::FromExploded(bool is_local, const Exploded& exploded) {
return Time(FileTimeToMicroseconds(ft));
}
+// static
+bool Time::FromExploded(bool is_local, const Exploded& exploded, Time& time) {
+ // Create the system struct representing our exploded time. It will either be
+ // in local time or UTC.
+ SYSTEMTIME st;
+ st.wYear = static_cast<WORD>(exploded.year);
+ st.wMonth = static_cast<WORD>(exploded.month);
+ st.wDayOfWeek = static_cast<WORD>(exploded.day_of_week);
+ st.wDay = static_cast<WORD>(exploded.day_of_month);
+ st.wHour = static_cast<WORD>(exploded.hour);
+ st.wMinute = static_cast<WORD>(exploded.minute);
+ st.wSecond = static_cast<WORD>(exploded.second);
+ st.wMilliseconds = static_cast<WORD>(exploded.millisecond);
+
+ FILETIME ft;
+ bool success = true;
+ // Ensure that it's in UTC.
+ if (is_local) {
+ SYSTEMTIME utc_st;
+ success = TzSpecificLocalTimeToSystemTime(NULL, &st, &utc_st) &&
mmenke 2016/05/20 19:44:57 nit: nullptr is now preferred over NULL.
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
+ SystemTimeToFileTime(&utc_st, &ft);
+ } else {
+ success = !!SystemTimeToFileTime(&st, &ft);
+ }
+
+ if (!success) {
+ NOTREACHED() << "Unable to convert time";
mmenke 2016/05/20 19:44:57 Looks like this NOTREACHED is incorrect (In the ol
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
+ time = Time(0);
+ return false;
+ }
+
+ time = Time(FileTimeToMicroseconds(ft));
+ return true;
+}
+
void Time::Explode(bool is_local, Exploded* exploded) const {
if (us_ < 0LL) {
// We are not able to convert it to FILETIME.
« base/time/time_posix.cc ('K') | « base/time/time_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698