/**
@brief checks if the values are usable
*/
-bool WeekCron::is_sane()
+bool WeekCron::is_sane() const
{
- if (begin < 0 || begin > 86399)
+ if (Begin < 0 || Begin > 86399)
return false;
- if (every != -1)
+ if (Every != -1)
{
- if (end < 0 || end > 86400 ||
- every < 1 || every > 86400 ||
- begin > end)
+ if (End < 0 || End > 86400 ||
+ Every < 1 || Every > 86400 ||
+ Begin > End)
return false;
}
if (calc_from <= 86400*14)
throw std::runtime_error("WeekCron doesn't work for times near 0");
- if (week.none_set())
+ if (Week.none_set())
return 0;
- if (every == -1)
+ if (Every == -1)
{
// point in time
- return get_next_point(calc_from,begin,true);
+ return get_next_point(calc_from,Begin,true);
}
else
{
// interval
- if (get_next_point(calc_from,begin,true) > get_next_point(calc_from,end-1,true))
+ if (get_next_point(calc_from,Begin,true) > get_next_point(calc_from,End-1,true))
{
// next begin > next end means we are at the begin or within the interval
- time_t interval_begin=get_lastnow_point(calc_from,begin,true);
+ time_t interval_begin=get_lastnow_point(calc_from,Begin,true);
time_t within_interval=calc_from - interval_begin;
- time_t since_lastrun=within_interval % every;
- time_t next_exec=calc_from+(every-since_lastrun);
+ time_t since_lastrun=within_interval % Every;
+ time_t next_exec=calc_from+(Every-since_lastrun);
// next step at or after end?
- if (next_exec >= get_next_point(calc_from,end,true))
- return get_next_point(calc_from,begin,true);
+ if (next_exec >= get_next_point(calc_from,End,true))
+ return get_next_point(calc_from,Begin,true);
else
return next_exec;
}
else
{
// next begin < next end means we are out of the interval: next begin is next run
- return get_next_point(calc_from,begin,true);
+ return get_next_point(calc_from,Begin,true);
}
}
}
localtime_r(&calc_from,&ft);
// take care of the weekday
- ft.tm_mday+=week.days_till_set(static_cast<WEEK::WEEKDAY>(ft.tm_wday));
+ ft.tm_mday+=Week.days_till_set(static_cast<WEEK::WEEKDAY>(ft.tm_wday));
ft.tm_hour=0;
ft.tm_min=0;
localtime_r(&calc_from,&ft);
// take care of the weekday
- ft.tm_mday-=week.days_since_set(static_cast<WEEK::WEEKDAY>(ft.tm_wday));
+ ft.tm_mday-=Week.days_since_set(static_cast<WEEK::WEEKDAY>(ft.tm_wday));
ft.tm_hour=0;
ft.tm_min=0;
{
private:
- int begin;
- int end;
- int every;
- WEEK week;
+ int Begin;
+ int End;
+ int Every;
+ WEEK Week;
time_t get_next_point(time_t calc_from, int daysec,bool todaycheck);
time_t get_lastnow_point(time_t calc_from, int daysec,bool todaycheck);
public:
WeekCron(void)
- : begin(0), end(0), every(-1), week()
+ : Begin(0), End(0), Every(-1)
{ }
- WeekCron(const std::string& daystring, int _begin)
- : begin(_begin), end(0), every(-1), week(daystring)
+ WeekCron(const std::string& daystring, int begin)
+ : Begin(begin), End(0), Every(-1), Week(daystring)
{ }
- WeekCron(const std::string& daystring, int _begin, int _end, int _every)
- : begin(_begin), end(_end), every(_every), week(daystring)
+ WeekCron(const std::string& daystring, int begin, int end, int every)
+ : Begin(begin), End(end), Every(every), Week(daystring)
{ }
- bool is_sane();
+ bool is_sane() const;
time_t get_next_run(time_t calc_from=0);