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

Side by Side Diff: base/time.cc

Issue 16093026: Provide nanoseconds precision for base::PlatformFileInfo on POSIX (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: st_?time_nsec doe not exist in the bots' NDK, use FromTimeT for Android Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/time.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/time.h" 5 #include "base/time.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include <float.h> 9 #include <float.h>
10 #endif 10 #endif
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 if (is_null()) 109 if (is_null())
110 return 0; // Preserve 0 so we can tell it doesn't exist. 110 return 0; // Preserve 0 so we can tell it doesn't exist.
111 if (is_max()) { 111 if (is_max()) {
112 // Preserve max without offset to prevent overflow. 112 // Preserve max without offset to prevent overflow.
113 return std::numeric_limits<double>::max(); 113 return std::numeric_limits<double>::max();
114 } 114 }
115 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / 115 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) /
116 static_cast<double>(kMicrosecondsPerSecond)); 116 static_cast<double>(kMicrosecondsPerSecond));
117 } 117 }
118 118
119 #if defined(OS_POSIX)
120 // static
121 Time Time::FromTimeSpec(const timespec& ts) {
122 return FromDoubleT(ts.tv_sec +
123 static_cast<double>(ts.tv_nsec) /
124 base::Time::kNanosecondsPerSecond);
125 }
126 #endif
127
119 // static 128 // static
120 Time Time::FromJsTime(double ms_since_epoch) { 129 Time Time::FromJsTime(double ms_since_epoch) {
121 // The epoch is a valid time, so this constructor doesn't interpret 130 // The epoch is a valid time, so this constructor doesn't interpret
122 // 0 as the null time. 131 // 0 as the null time.
123 if (ms_since_epoch == std::numeric_limits<double>::max()) 132 if (ms_since_epoch == std::numeric_limits<double>::max())
124 return Max(); 133 return Max();
125 return Time(static_cast<int64>(ms_since_epoch * kMicrosecondsPerMillisecond) + 134 return Time(static_cast<int64>(ms_since_epoch * kMicrosecondsPerMillisecond) +
126 kTimeTToMicrosecondsOffset); 135 kTimeTToMicrosecondsOffset);
127 } 136 }
128 137
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return is_in_range(month, 1, 12) && 196 return is_in_range(month, 1, 12) &&
188 is_in_range(day_of_week, 0, 6) && 197 is_in_range(day_of_week, 0, 6) &&
189 is_in_range(day_of_month, 1, 31) && 198 is_in_range(day_of_month, 1, 31) &&
190 is_in_range(hour, 0, 23) && 199 is_in_range(hour, 0, 23) &&
191 is_in_range(minute, 0, 59) && 200 is_in_range(minute, 0, 59) &&
192 is_in_range(second, 0, 60) && 201 is_in_range(second, 0, 60) &&
193 is_in_range(millisecond, 0, 999); 202 is_in_range(millisecond, 0, 999);
194 } 203 }
195 204
196 } // namespace base 205 } // namespace base
OLDNEW
« no previous file with comments | « base/time.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698