OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ASH_SYSTEM_NIGHT_LIGHT_TIME_OF_DAY_H_ |
| 6 #define ASH_SYSTEM_NIGHT_LIGHT_TIME_OF_DAY_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "ash/ash_export.h" |
| 11 #include "base/time/time.h" |
| 12 |
| 13 namespace ash { |
| 14 |
| 15 // Represents the time of the day as a simple number of minutes since 00:00 |
| 16 // regardless of the date or the timezone. This makes it simple to persist this |
| 17 // as an integer user pref. |
| 18 class ASH_EXPORT TimeOfDay { |
| 19 public: |
| 20 // |offset_minutes| is the number of minutes since 00:00. If |offset_minutes| |
| 21 // is equal to the offset minutes in 24 hours, it will be reset to 0 to |
| 22 // represent the time 00:00 (12:00 AM). Offsets greater than the minutes in |
| 23 // 24 hours are not allowed. |
| 24 explicit TimeOfDay(int offset_minutes); |
| 25 TimeOfDay(const TimeOfDay& other) = default; |
| 26 TimeOfDay& operator=(const TimeOfDay& rhs) = default; |
| 27 ~TimeOfDay() = default; |
| 28 |
| 29 // Converts to a minutes offset representation from |time| dropping the |
| 30 // seconds and milliseconds. |
| 31 static TimeOfDay FromTime(const base::Time& time); |
| 32 |
| 33 bool operator==(const TimeOfDay& rhs) const; |
| 34 |
| 35 int offset_minutes_from_zero_hour() const { |
| 36 return offset_minutes_from_zero_hour_; |
| 37 } |
| 38 |
| 39 // Converts to an actual point in time today. If this fail for some reason, |
| 40 // base::Time() will be returned. |
| 41 base::Time ToTimeToday() const; |
| 42 |
| 43 // Converts to a string in the format "3:07 PM". |
| 44 std::string ToString() const; |
| 45 |
| 46 private: |
| 47 int offset_minutes_from_zero_hour_; |
| 48 }; |
| 49 |
| 50 } // namespace ash |
| 51 |
| 52 #endif // ASH_SYSTEM_NIGHT_LIGHT_TIME_OF_DAY_H_ |
OLD | NEW |