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

Unified Diff: ash/system/night_light/time_of_day.h

Issue 2887913004: [Night Light] CL4: Automatic schedule backend. (Closed)
Patch Set: Nits Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/night_light/night_light_controller_unittest.cc ('k') | ash/system/night_light/time_of_day.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/night_light/time_of_day.h
diff --git a/ash/system/night_light/time_of_day.h b/ash/system/night_light/time_of_day.h
new file mode 100644
index 0000000000000000000000000000000000000000..ed68ea6dce88f4f70db9a27d97984f97f700e674
--- /dev/null
+++ b/ash/system/night_light/time_of_day.h
@@ -0,0 +1,52 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_SYSTEM_NIGHT_LIGHT_TIME_OF_DAY_H_
+#define ASH_SYSTEM_NIGHT_LIGHT_TIME_OF_DAY_H_
+
+#include <string>
+
+#include "ash/ash_export.h"
+#include "base/time/time.h"
+
+namespace ash {
+
+// Represents the time of the day as a simple number of minutes since 00:00
+// regardless of the date or the timezone. This makes it simple to persist this
+// as an integer user pref.
+class ASH_EXPORT TimeOfDay {
+ public:
+ // |offset_minutes| is the number of minutes since 00:00. If |offset_minutes|
+ // is equal to the offset minutes in 24 hours, it will be reset to 0 to
+ // represent the time 00:00 (12:00 AM). Offsets greater than the minutes in
+ // 24 hours are not allowed.
+ explicit TimeOfDay(int offset_minutes);
+ TimeOfDay(const TimeOfDay& other) = default;
+ TimeOfDay& operator=(const TimeOfDay& rhs) = default;
+ ~TimeOfDay() = default;
+
+ // Converts to a minutes offset representation from |time| dropping the
+ // seconds and milliseconds.
+ static TimeOfDay FromTime(const base::Time& time);
+
+ bool operator==(const TimeOfDay& rhs) const;
+
+ int offset_minutes_from_zero_hour() const {
+ return offset_minutes_from_zero_hour_;
+ }
+
+ // Converts to an actual point in time today. If this fail for some reason,
+ // base::Time() will be returned.
+ base::Time ToTimeToday() const;
+
+ // Converts to a string in the format "3:07 PM".
+ std::string ToString() const;
+
+ private:
+ int offset_minutes_from_zero_hour_;
+};
+
+} // namespace ash
+
+#endif // ASH_SYSTEM_NIGHT_LIGHT_TIME_OF_DAY_H_
« no previous file with comments | « ash/system/night_light/night_light_controller_unittest.cc ('k') | ash/system/night_light/time_of_day.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698