#include <cron.hpp>
/**
- @brief checks if the values are usable
-*/
+ * 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)
+ : Begin(begin)
+ , End(0)
+ , Every(-1)
+ , Week(daystring)
+{
+}
+
+/**
+ * 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
+ * @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)
+ : Begin(begin)
+ , End(end)
+ , Every(every)
+ , Week(daystring)
+{
+}
+
+
+/**
+ * Checks if the input values are sane
+ * @return True if sane, false otherweise
+ */
bool WeekCron::is_sane() const
{
if (Begin < 0 || Begin > 86399)
}
/**
- @brief returns the next point in time the item is scheduled for
- @param calc_from unix-time to start calculating from (0 means now)
- @note if it is scheduled for calc_from we return the next schedule, not now!
-*/
+ * Returns the next point in time the item is scheduled for. Also handles intervals.
+ * @note if it is scheduled for calc_from we return the next schedule, not now!
+ * @param calc_from unix-time to start calculating from (0 means now)
+ * @return Next point in time the item is scheduled for
+ */
time_t WeekCron::get_next_run(time_t calc_from)
{
if (!calc_from)
}
}
+/**
+ * Returns the next point in time the item is scheduled for
+ * @param calc_from Point of time to start calculations from
+ * @param daysec Start point of time in seconds since the start of the day
+ * @param todaycheck If true we check if the calculated time point is before
+ our #calc_from calcucation start point.
+ 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)
{
struct tm ft;
return target;
}
+/**
+ * Returns the last point in time the item is scheduled for
+ * @param calc_from Point of time to start calculations from
+ * @param daysec Start point of time in seconds since the start of the day
+ * @param todaycheck If true we check if the calculated time point is before
+ our #calc_from calcucation start point.
+ If yes, we will advance to the next day.
+ * @return Last point in time
+ * FIXME: Is the description correct?
+ */
time_t WeekCron::get_lastnow_point(time_t calc_from, int daysec, bool todaycheck)
{
struct tm ft;
return target;
}
-
#include <timefunc.hxx>
+/// Time points and intervals repeating each week
/**
- @brief time-points and intervals repeating each week
- @note begin and end are given in seconds since start of the day
+ This class represents recurring time points and intervals
+ which can be repeated on configurable days of the week.
*/
class WeekCron
{
private:
-
+ /// Start point of time in seconds since the start of the day
int Begin;
+ /// End point of time in seconds since the start of the day. Only used when #Every != -1
int End;
+ /// Repeat event every xxx seconds in the half-open interval of #Begin and #End. -1 is disabled
int Every;
+ /// 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);
public:
-
- WeekCron(void)
- : 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, int end, int every)
- : Begin(begin), End(end), Every(every), Week(daystring)
- { }
+ WeekCron(const std::string& daystring, int begin);
+ WeekCron(const std::string& daystring, int begin, int end, int every);
bool is_sane() const;