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

Side by Side Diff: ash/system/night_light/night_light_time.cc

Issue 2887913004: [Night Light] CL4: Automatic schedule backend. (Closed)
Patch Set: Working Created 3 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 unified diff | Download patch
OLDNEW
(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 #include "ash/system/night_light/night_light_time.h"
6 #include <base/i18n/time_formatting.h>
James Cook 2017/05/23 16:34:59 nit: blank line above, and no <>
afakhry 2017/05/24 04:21:10 Done.
7 #include <base/strings/utf_string_conversions.h>
James Cook 2017/05/23 16:34:59 no <>
afakhry 2017/05/24 04:21:10 Done.
8
9 namespace ash {
10
11 namespace {
12
13 constexpr int kMaxOffsetMinutes = 24 * 60;
14
15 } // namespace
16
17 NightLightTime::NightLightTime(int offset_minutes)
18 : offset_minutes_from_zero_hour_(
19 offset_minutes == kMaxOffsetMinutes ? 0 : offset_minutes) {
20 DCHECK_LE(offset_minutes_from_zero_hour_, kMaxOffsetMinutes);
21 }
22
23 NightLightTime::NightLightTime(const NightLightTime& other)
24 : offset_minutes_from_zero_hour_(other.offset_minutes_from_zero_hour_) {}
25
26 // static
27 NightLightTime NightLightTime::FromTime(const base::Time& time) {
28 base::Time::Exploded exploded;
29 time.LocalExplode(&exploded);
30 return NightLightTime(exploded.hour * 60 + exploded.minute);
31 }
32
33 NightLightTime& NightLightTime::operator=(const NightLightTime& rhs) {
34 if (this != &rhs)
35 offset_minutes_from_zero_hour_ = rhs.offset_minutes_from_zero_hour_;
36
37 return *this;
38 }
39
40 bool NightLightTime::operator==(const NightLightTime& rhs) const {
41 return offset_minutes_from_zero_hour_ == rhs.offset_minutes_from_zero_hour_;
42 }
43
44 base::Time NightLightTime::ToTime() const {
45 base::Time::Exploded now;
46 base::Time::Now().LocalExplode(&now);
47 now.hour = (offset_minutes_from_zero_hour_ / 60) % 24;
48 now.minute = offset_minutes_from_zero_hour_ % 60;
49 now.second = 0;
50 now.millisecond = 0;
51 base::Time result;
52 CHECK(base::Time::FromLocalExploded(now, &result));
James Cook 2017/05/23 16:34:59 Will this CHECK-fail and crash at 12:30 AM during
afakhry 2017/05/24 04:21:11 It seems that we have code to handle this case: ht
53 return result;
54 }
55
56 std::string NightLightTime::ToString() const {
57 return base::UTF16ToUTF8(base::TimeFormatTimeOfDay(ToTime()));
58 }
59
60 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698