*
*/
#include <time.h>
-
#include <stdexcept>
-
#include <cron.hpp>
+namespace I2n
+{
+
/**
* Constructor
* @param daystring String representing the active weekdays as numbers. 0 is Sunday.
* @param begin Start point of time in seconds since the start of the day
*/
-WeekCron::WeekCron(const std::string& daystring, int begin)
+WeekCron::WeekCron(const std::string& daystring, const int begin)
: Begin(begin)
, End(0)
, Every(-1)
* @param end End point of time in seconds since the start of the day. Only used when every != -1
* @param every Repeat event every xxx seconds in the half-open interval of begin and end. -1 is disabled
*/
-WeekCron::WeekCron(const std::string& daystring, int begin, int end, int every)
+WeekCron::WeekCron(const std::string& daystring, const int begin, const int end, const int every)
: Begin(begin)
, End(end)
, Every(every)
throw std::runtime_error("illegal cron value");
if (calc_from <= 86400*14)
- throw std::runtime_error("WeekCron doesn't work for times near 0");
+ throw std::runtime_error("WeekCron doesn't work for timestamps near 0");
if (Week.none_set())
return 0;
else
{
// interval
- if (get_next_point(calc_from,Begin,true) > get_next_point(calc_from,End-1,true))
+ time_t next_begin = get_next_point(calc_from,Begin,true);
+ if (next_begin > get_next_point(calc_from,End-1,true))
{
// next begin > next end means we are at the begin or within the interval
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 next_begin;
}
}
}
If yes, we will advance to the next day.
* @return Next point in time
*/
-time_t WeekCron::get_next_point(time_t calc_from, int daysec, bool todaycheck)
+time_t WeekCron::get_next_point(const time_t calc_from, const int daysec, const bool todaycheck)
{
struct tm ft;
localtime_r(&calc_from,&ft);
* @return Last point in time
* FIXME: Is the description correct?
*/
-time_t WeekCron::get_lastnow_point(time_t calc_from, int daysec, bool todaycheck)
+time_t WeekCron::get_lastnow_point(const time_t calc_from, const int daysec, const bool todaycheck)
{
struct tm ft;
localtime_r(&calc_from,&ft);
return target;
}
+
+}
\ No newline at end of file
#define __CRON_HPP
#include <time.h>
-
#include <timefunc.hxx>
+namespace I2n
+{
+
/// Time points and intervals repeating each week
/**
This class represents recurring time points and intervals
/// Stores the active days this WeekCron is valid for
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);
+ time_t get_next_point(const time_t calc_from, const int daysec, const bool todaycheck);
+ time_t get_lastnow_point(const time_t calc_from, const int daysec, const bool todaycheck);
public:
- WeekCron(const std::string& daystring, int begin);
- WeekCron(const std::string& daystring, int begin, int end, int every);
+ WeekCron(const std::string& daystring, const int begin);
+ WeekCron(const std::string& daystring, const int begin, const int end, const int every);
bool is_sane() const;
};
+}
+
#endif