libcommonc++  0.7
TimeSpec.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_TimeSpec_hxx
24 #define __ccxx_TimeSpec_hxx
25 
26 #include <commonc++/Common.h++>
27 #include <commonc++/BitSet.h++>
28 #include <commonc++/DateTime.h++>
29 #include <commonc++/String.h++>
30 
31 namespace ccxx {
32 
64 {
65  public:
66 
68  TimeSpec();
69 
71  TimeSpec(const DateTime& time);
72 
77  TimeSpec(uint_t hour, uint_t minute);
78 
83  TimeSpec(uint_t hour, uint_t minute, uint_t month, uint_t day);
84 
86  TimeSpec(const String& spec);
87 
89  virtual ~TimeSpec();
90 
92  void setSpec(const String& spec);
93 
100  TimeSpec& setMonth(uint_t month);
101 
109  TimeSpec& setMonths(uint_t month1, uint_t month2);
110 
117  TimeSpec& clearMonth(uint_t month);
118 
126  TimeSpec& clearMonths(uint_t month1, uint_t month2);
127 
129  TimeSpec& setAllMonths();
130 
132  TimeSpec& clearAllMonths();
133 
140  TimeSpec& setDay(uint_t day);
141 
149  TimeSpec& setDays(uint_t day1, uint_t day2);
150 
157  TimeSpec& clearDay(uint_t day);
158 
166  TimeSpec& clearDays(uint_t day1, uint_t day2);
167 
169  TimeSpec& setAllDays();
170 
172  TimeSpec& clearAllDays();
173 
182  TimeSpec& setDayOfWeek(uint_t dow);
183 
195  TimeSpec& setDaysOfWeek(uint_t dow1, uint_t dow2);
196 
205  TimeSpec& clearDayOfWeek(uint_t dow);
206 
218  TimeSpec& clearDaysOfWeek(uint_t dow1, uint_t dow2);
219 
221  TimeSpec& setAllDaysOfWeek();
222 
224  TimeSpec& clearAllDaysOfWeek();
225 
232  TimeSpec& setHour(uint_t hour);
233 
241  TimeSpec& setHours(uint_t hour1, uint_t hour2);
242 
249  TimeSpec& clearHour(uint_t hour);
250 
258  TimeSpec& clearHours(uint_t hour1, uint_t hour2);
259 
261  TimeSpec& setAllHours();
262 
264  TimeSpec& clearAllHours();
265 
272  TimeSpec& setMinute(uint_t minute);
273 
281  TimeSpec& setMinutes(uint_t minute1, uint_t minute2);
282 
289  TimeSpec& clearMinute(uint_t minute);
290 
298  TimeSpec& clearMinutes(uint_t minute1, uint_t minute2);
299 
301  TimeSpec& setAllMinutes();
302 
304  TimeSpec& clearAllMinutes();
305 
312  bool matches(time_s_t time) const;
313 
320  bool matches(time_ms_t time) const;
321 
332  bool matches(uint_t month, uint_t day, uint_t weekday, uint_t hour,
333  uint_t minute) const;
334 
336  String toString() const;
337 
338  private:
339 
340  void _parseValues(String str, uint_t base, BitSet& set);
341  void _set(BitSet& bset, uint_t base, uint_t pos, bool set);
342  void _setRange(BitSet& bset, uint_t base, uint_t min, uint_t max, bool set);
343  void _format(const BitSet& set, uint_t base, String& s) const;
344 
345  BitSet _months;
346  BitSet _days;
347  BitSet _dow;
348  BitSet _hours;
349  BitSet _minutes;
350 };
351 
352 } // namespace ccxx
353 
354 #endif // __ccxx_TimeSpec_hxx
int64_t time_ms_t
A time expressed in milliseconds since the epoch (00:00:00, UTC, January 1, 1970).
Definition: Integers.h++:98
int32_t time_s_t
A time expressed in seconds since the epoch (00:00:00, UTC, January 1, 1970).
Definition: Integers.h++:85
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
A compact representation of an array of bits (boolean values).
Definition: BitSet.h++:42
A time specification, such as that used by cron servers.
Definition: TimeSpec.h++:63
#define COMMONCPP_API
Definition: Common.h++:126
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
A representation of a calendar date and clock time.
Definition: DateTime.h++:38
Definition: AllocationMap.c++:25