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

Unified Diff: base/time/time.h

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
« no previous file with comments | « no previous file | base/time/time.cc » ('j') | base/time/time_mac.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time.h
diff --git a/base/time/time.h b/base/time/time.h
index 9fce71b581e4ca27c216e31cb40ab78b867760ea..ede6ebd6a756d7dc4efa6c0612a1f1f266f7539d 100644
--- a/base/time/time.h
+++ b/base/time/time.h
@@ -420,6 +420,7 @@ class BASE_EXPORT Time : public time_internal::TimeBase<Time> {
// respective ranges. A 'true' return value does not guarantee the
// Exploded value can be successfully converted to a Time value.
bool HasValidValues() const;
+ bool operator!=(const Exploded& rhs);
};
// Contains the NULL time. Use Time::Now() to get the current time.
@@ -522,6 +523,20 @@ class BASE_EXPORT Time : public time_internal::TimeBase<Time> {
return FromExploded(true, exploded);
}
+ // Converts an exploded structure representing either the local time or UTC
+ // into a Time class.
+ // This is a transition to a new format, where the converted time is set to
+ // |time| and FromUTCExploded, FromLocalExploded and FromExploded return true
+ // on success or false on failure. For example, FromExploded can fail when
+ // 31st of a month is set on a 28-30 day month, which results in 1st day of
+ // the next month.
+ static bool FromUTCExploded(const Exploded& exploded, Time& time) {
mmenke 2016/05/20 19:44:56 Per Google C++ style guide, non-const refs are for
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
+ return FromExploded(false, exploded, time);
+ }
+ static bool FromLocalExploded(const Exploded& exploded, Time& time) {
mmenke 2016/05/20 19:44:56 These two should use WARN_UNUSED_RESULT.
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
+ return FromExploded(true, exploded, time);
+ }
mmenke 2016/05/20 19:44:56 Is the plan to replace calls to the old methods wi
maksims (do not use this acc) 2016/05/24 09:14:21 Yes, I would like to do so.
+
// Converts a string representation of time to a Time object.
// An example of a time string which is converted is as below:-
// "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified
@@ -563,6 +578,13 @@ class BASE_EXPORT Time : public time_internal::TimeBase<Time> {
// |is_local = true| or UTC |is_local = false|.
static Time FromExploded(bool is_local, const Exploded& exploded);
mmenke 2016/05/20 19:44:56 If we're going to keep the old methods around (Per
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
+ // Unexplodes a given time assuming the source is either local time
+ // |is_local = true| or UTC |is_local = false|.
+ // This is a transition to a newer form. Function returns false on failure
+ // and sets |time| to Time(0). Otherwise returns true and sets |time| to
+ // non-exploded time.
+ static bool FromExploded(bool is_local, const Exploded& exploded, Time& time);
mmenke 2016/05/20 19:44:56 WARN_UNUSED_RESULT
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
+
// Converts a string representation of time to a Time object.
// An example of a time string which is converted is as below:-
// "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified
« no previous file with comments | « no previous file | base/time/time.cc » ('j') | base/time/time_mac.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698