*
*/
#include <time.h>
-
#include <stdexcept>
- #include <iostream>
+
#include <cron.hpp>
+ namespace I2n {
+ namespace Time {
+
+const time_t WeekCron::StNimmerleinsDay = static_cast<time_t>(-1);
+
/**
* Constructor
* @param daystring String representing the active weekdays as numbers. 0 is Sunday.
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;
+ return StNimmerleinsDay;
if (Every == -1)
{
}
/**
- * Returns the last point in time the item is scheduled for
+ * Returns the previous or current point in time the item was scheduled for.
+ * Does not care about intervals.
+ * Returns #calc_from if scheduled for #calc_from.
* @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
+ * @param todaycheck If true we check if the calculated time point is after
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?
+ If yes, we will go back to the previos day
+ * @return Previous point in time
*/
- time_t WeekCron::get_previousnow_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)
++time_t WeekCron::get_previousnow_point(const time_t calc_from, const int daysec, const bool todaycheck)
{
struct tm ft;
localtime_r(&calc_from,&ft);
#define __CRON_HPP
#include <time.h>
+ #include <week.hpp>
- #include <timefunc.hxx>
+ namespace I2n {
+ namespace Time {
-/// Time points and intervals repeating each week
/**
+ @brief Time points and intervals repeating each week
This class represents recurring time points and intervals
which can be repeated on configurable days of the week.
*/
/// 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;
+ I2n::Time::Week Week;
- time_t get_next_point(time_t calc_from, int daysec,bool todaycheck);
- time_t get_previousnow_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);
++ time_t get_previousnow_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;