repetitive-interval.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_REPETITIVE_INTERVAL_HPP
24 #define NDN_REPETITIVE_INTERVAL_HPP
25 
26 #include "interval.hpp"
27 
28 namespace ndn {
29 
36 public:
37  enum RepeatUnit {
38  NONE = 0,
39  DAY = 1,
40  MONTH = 2,
41  YEAR = 3
42  };
43 
44  class Result {
45  public:
46  Result(bool isPositive, const Interval& interval)
47  {
48  this->isPositive = isPositive;
49  this->interval = interval;
50  }
51 
52  bool isPositive;
53  Interval interval;
54  };
55 
60 
76  (MillisecondsSince1970 startDate, MillisecondsSince1970 endDate,
77  int intervalStartHour, int intervalEndHour, int nRepeats = 0,
78  RepeatUnit repeatUnit = RepeatUnit::NONE);
79 
90  Result
91  getInterval(MillisecondsSince1970 timePoint) const;
92 
98  int
99  compare(const RepetitiveInterval& other) const;
100 
106  getStartDate() const { return startDate_; }
107 
113  getEndDate() const { return endDate_; }
114 
119  int
120  getIntervalStartHour() const { return intervalStartHour_; }
121 
126  int
127  getIntervalEndHour() const { return intervalEndHour_; }
128 
133  int
134  getNRepeats() const { return nRepeats_; }
135 
140  RepeatUnit
141  getRepeatUnit() const { return repeatUnit_; }
142 
143 private:
144  friend class Schedule;
145 
151  bool
152  hasIntervalOnDate(MillisecondsSince1970 timePoint) const;
153 
159  static MillisecondsSince1970
160  toDateOnlyMilliseconds(MillisecondsSince1970 timePoint);
161 
162  static const uint64_t MILLISECONDS_IN_HOUR = 3600 * 1000;
163  static const uint64_t MILLISECONDS_IN_DAY = 24 * 3600 * 1000;
164  MillisecondsSince1970 startDate_;
165  MillisecondsSince1970 endDate_;
166  int intervalStartHour_;
167  int intervalEndHour_;
168  int nRepeats_;
169  RepeatUnit repeatUnit_;
170 };
171 
172 }
173 
174 #endif
An Interval defines a time duration which contains a start timestamp and an end timestamp.
Definition: interval.hpp:36
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
Schedule is used to manage the times when a member can access data using two sets of RepetitiveInterv...
Definition: schedule.hpp:43
Result getInterval(MillisecondsSince1970 timePoint) const
Get an interval that covers the time point.
Definition: repetitive-interval.cpp:78
MillisecondsSince1970 getEndDate() const
Get the end date.
Definition: repetitive-interval.hpp:113
int getIntervalStartHour() const
Get the interval start hour.
Definition: repetitive-interval.hpp:120
int compare(const RepetitiveInterval &other) const
Compare this to the other RepetitiveInterval.
Definition: repetitive-interval.cpp:116
int getIntervalEndHour() const
Get the interval end hour.
Definition: repetitive-interval.hpp:127
A RepetitiveInterval is an advanced interval which can repeat and can be used to find a simple Interv...
Definition: repetitive-interval.hpp:35
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:117
MillisecondsSince1970 getStartDate() const
Get the start date.
Definition: repetitive-interval.hpp:106
RepeatUnit getRepeatUnit() const
Get the repeat unit.
Definition: repetitive-interval.hpp:141
Definition: repetitive-interval.hpp:44
int getNRepeats() const
Get the number of repeats.
Definition: repetitive-interval.hpp:134
RepetitiveInterval()
Create a default RepetitiveInterval with one day duration, non-repeating.
Definition: repetitive-interval.cpp:39