File: weekly_time_interval_checked.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (73 lines) | stat: -rw-r--r-- 2,657 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_POLICY_WEEKLY_TIME_WEEKLY_TIME_INTERVAL_CHECKED_H_
#define CHROMEOS_ASH_COMPONENTS_POLICY_WEEKLY_TIME_WEEKLY_TIME_INTERVAL_CHECKED_H_

#include <optional>

#include "base/component_export.h"
#include "base/values.h"
#include "chromeos/ash/components/policy/weekly_time/weekly_time_checked.h"

namespace policy {

// `WeeklyTimeIntervalChecked` corresponds to the same type from
// `components/policy/resources/templates/common_schemas.yaml`. It is used to
// read and unpack the policy value into a proper C++ type.
//
// It represents a non-empty time interval [start, end) between two weekly
// times. It can be wrapped around the end of the week.
//
// It is different from `WeeklyTimeInterval` in that it is checked automatically
// during policy decoding for validity, and it also doesn't have the timezone
// info tacked on top.
class COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_POLICY)
    WeeklyTimeIntervalChecked {
 public:
  // Test support.
  static const char kStart[];
  static const char kEnd[];

  WeeklyTimeIntervalChecked(const WeeklyTimeChecked& start,
                            const WeeklyTimeChecked& end);
  WeeklyTimeIntervalChecked(const WeeklyTimeIntervalChecked&);
  WeeklyTimeIntervalChecked& operator=(const WeeklyTimeIntervalChecked&);

  friend bool operator==(const WeeklyTimeIntervalChecked&,
                         const WeeklyTimeIntervalChecked&) = default;

  // Determines if `interval_a` and `interval_b` have any overlap in time.
  // Intervals are considered half-open (i.e., the start time is included, the
  // end time is not).
  static bool IntervalsOverlap(const WeeklyTimeIntervalChecked& a,
                               const WeeklyTimeIntervalChecked& b);

  // Constructs from a Value::Dict:
  // {
  //   "start": WeeklyTimeChecked,
  //   "end": WeeklyTimeChecked
  // }
  static std::optional<WeeklyTimeIntervalChecked> FromDict(
      const base::Value::Dict& dict);

  // Duration of the current interval [start_, end_). NB: Duration of interval
  // where `start_` == `end_` is defined as 1 week and not 0.
  base::TimeDelta Duration() const;

  // Check if `w` is in [`start_`, `end_`).
  bool Contains(const WeeklyTimeChecked& w) const;

  WeeklyTimeChecked start() const { return start_; }

  WeeklyTimeChecked end() const { return end_; }

 private:
  WeeklyTimeChecked start_;
  WeeklyTimeChecked end_;
};

}  // namespace policy

#endif  // CHROMEOS_ASH_COMPONENTS_POLICY_WEEKLY_TIME_WEEKLY_TIME_INTERVAL_CHECKED_H_