Chromium Code Reviews| 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. |