Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/croncpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ namespace cron
friend std::string to_cronstr(cronexpr const& cex);
friend std::string to_string(cronexpr const & cex);

friend bool is_initialized(cronexpr const& cex);

template <typename Traits>
friend cronexpr make_cron(CRONCPP_STRING_VIEW expr);
};
Expand All @@ -230,6 +232,10 @@ namespace cron
return !(e1 == e2);
}

inline bool is_initialized(cronexpr const& cex ){
return !cex.expr.empty();
}

inline std::string to_string(cronexpr const & cex)
{
return
Expand Down Expand Up @@ -865,6 +871,8 @@ namespace cron
template <typename Traits = cron_standard_traits>
static std::tm cron_next(cronexpr const & cex, std::tm date)
{
if(!is_initialized(cex))
throw bad_cronexpr("Cron expr is not initialized");
time_t original = utils::tm_to_time(date);
if (INVALID_TIME == original) return {};

Expand All @@ -887,6 +895,8 @@ namespace cron
template <typename Traits = cron_standard_traits>
static std::time_t cron_next(cronexpr const & cex, std::time_t const & date)
{
if(!is_initialized(cex))
throw bad_cronexpr("Cron expr is not initialized");
std::tm val;
std::tm* dt = utils::time_to_tm(&date, &val);
if (dt == nullptr) return INVALID_TIME;
Expand Down