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

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: mmenke comments 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 399ec826ce375e2adeeb5c8b58b1a9aeef18edb8..0c25a95b147ae5f40dffca8c22a72812fb18964c 100644
--- a/base/time/time.h
+++ b/base/time/time.h
@@ -56,6 +56,7 @@
#include <limits>
#include "base/base_export.h"
+#include "base/compiler_specific.h"
#include "base/numerics/safe_math.h"
#include "build/build_config.h"
@@ -424,6 +425,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);
Mark Mentovai 2016/05/24 18:27:27 Put a blank line before this, because it’s not rel
mmenke 2016/05/24 18:31:18 I'm not sure we can check day of week...So as I be
Mark Mentovai 2016/05/24 18:34:13 mmenke wrote:
maksims (do not use this acc) 2016/05/26 04:38:18 Done.
};
// Contains the NULL time. Use Time::Now() to get the current time.
@@ -520,10 +522,29 @@ class BASE_EXPORT Time : public time_internal::TimeBase<Time> {
// Converts an exploded structure representing either the local time or UTC
// into a Time class.
mmenke 2016/05/24 16:08:33 Should add a TODO here: TODO(maksims): Get rid o
maksims (do not use this acc) 2016/05/26 04:38:18 Done.
static Time FromUTCExploded(const Exploded& exploded) {
- return FromExploded(false, exploded);
+ base::Time time;
+ ignore_result(FromExploded(false, exploded, &time));
+ return time;
}
static Time FromLocalExploded(const Exploded& exploded) {
- return FromExploded(true, exploded);
+ base::Time time;
+ ignore_result(FromExploded(true, exploded, &time));
+ return time;
+ }
+
+ // 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,
mmenke 2016/05/24 16:08:33 Think your second sentence shouldn't refer to the
maksims (do not use this acc) 2016/05/26 04:38:18 Done.
+ // 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) WARN_UNUSED_RESULT {
+ return FromExploded(false, exploded, time);
+ }
+ static bool FromLocalExploded(const Exploded& exploded,
+ Time* time) WARN_UNUSED_RESULT {
+ return FromExploded(true, exploded, time);
}
// Converts a string representation of time to a Time object.
@@ -564,8 +585,12 @@ class BASE_EXPORT Time : public time_internal::TimeBase<Time> {
void Explode(bool is_local, Exploded* exploded) const;
// Unexplodes a given time assuming the source is either local time
- // |is_local = true| or UTC |is_local = false|.
- static Time FromExploded(bool is_local, const Exploded& exploded);
+ // |is_local = true| or UTC |is_local = false|. 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) WARN_UNUSED_RESULT;
// Converts a string representation of time to a Time object.
// An example of a time string which is converted is as below:-
« 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