22595f85126d03c797a667858b28adf5adf954c1
[libi2ncommon] / src / cron.hpp
1 /** @file
2  * @brief repeating time-points and intervals 
3  *
4  * @copyright Copyright © 2009 by Intra2net AG
5  * @license commercial
6  * @contact info@intra2net.com
7  *
8  */
9
10 #ifndef __CRON_HPP
11 #define __CRON_HPP
12
13 #include <time.h>
14 #include <week.hpp>
15
16 namespace I2n {
17 namespace Time {
18
19 /**
20     @brief Time points and intervals repeating each week
21     This class represents recurring time points and intervals
22     which can be repeated on configurable days of the week.
23 */
24 class WeekCron
25 {
26     public:
27         static const time_t StNimmerleinsDay;
28
29     private:
30         /// Start point of time in seconds since the start of the day
31         int Begin;
32         /// End point of time in seconds since the start of the day. Only used when #Every != -1
33         int End;
34         /// Repeat event every xxx seconds in the half-open interval of #Begin and #End. -1 is disabled
35         int Every;
36         /// Stores the active days this WeekCron is valid for
37         I2n::Time::Week Week;
38
39         time_t get_next_point(const time_t calc_from, const int daysec, const bool todaycheck) const;
40         time_t get_previousnow_point(const time_t calc_from, const int daysec, const bool todaycheck) const;
41         void fill_tm_with_wallclock(struct tm *ft, const int daysec) const;
42
43     public:
44         WeekCron();
45         WeekCron(const std::string& daystring, const int begin);
46         WeekCron(const std::string& daystring, const int begin, const int end, const int every);
47         WeekCron(const I2n::Time::Week& week, const int begin);
48         WeekCron(const I2n::Time::Week& week, const int begin, const int end, const int every);
49
50         // accessor functions
51         I2n::Time::Week get_week(void)
52             { return Week; }
53         void set_week(const I2n::Time::Week& week)
54             { Week=week; }
55         int get_begin(void)
56             { return Begin; }
57         void set_begin(const int begin)
58             { Begin=begin; }
59         int get_end(void)
60             { return End; }
61         void set_end(const int end)
62             { End=end; }
63         int get_every(void)
64             { return Every; }
65         void set_every(const int every)
66             { Every=every; }
67
68         bool is_sane() const;
69
70         time_t get_next_run(time_t calc_from=0) const;
71 };
72
73 }
74 }
75
76 #endif