Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ These special time specification tokens which replace the 5 initial time and dat

|Token|Meaning
| --- | --- |
| @yearly | Run once a year, ie. "0 0 1 1 *".
| @annually | Run once a year, ie. "0 0 1 1 *".
| @monthly | Run once a month, ie. "0 0 1 * *".
| @weekly | Run once a week, ie. "0 0 * * 0".
| @daily | Run once a day, ie. "0 0 * * *".
| @hourly | Run once an hour, ie. "0 * * * *".
| @yearly | Run once a year, ie. "0 0 0 1 1 *".
| @annually | Run once a year, ie. "0 0 0 1 1 *"".
| @monthly | Run once a month, ie. "0 0 0 1 * *".
| @weekly | Run once a week, ie. "0 0 0 * * 0".
| @daily | Run once a day, ie. "0 0 0 * * ?".
| @hourly | Run once an hour, ie. "0 0 * * * ?".

# Randomization

Expand Down
12 changes: 6 additions & 6 deletions libcron/src/CronData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ namespace libcron
{
// First, check for "convenience scheduling" using @yearly, @annually,
// @monthly, @weekly, @daily or @hourly.
std::string tmp = std::regex_replace(cron_expression, std::regex("@yearly"), "0 0 1 1 *");
tmp = std::regex_replace(tmp, std::regex("@annually"), "0 0 1 1 *");
tmp = std::regex_replace(tmp, std::regex("@monthly"), "0 0 1 * *");
tmp = std::regex_replace(tmp, std::regex("@weekly"), "0 0 * * 0");
tmp = std::regex_replace(tmp, std::regex("@daily"), "0 0 * * *");
const std::string expression = std::regex_replace(tmp, std::regex("@hourly"), "0 * * * *");
std::string tmp = std::regex_replace(cron_expression, std::regex("@yearly"), "0 0 0 1 1 *");
tmp = std::regex_replace(tmp, std::regex("@annually"), "0 0 0 1 1 *");
tmp = std::regex_replace(tmp, std::regex("@monthly"), "0 0 0 1 * *");
tmp = std::regex_replace(tmp, std::regex("@weekly"), "0 0 0 * * 0");
tmp = std::regex_replace(tmp, std::regex("@daily"), "0 0 0 * * ?");
const std::string expression = std::regex_replace(tmp, std::regex("@hourly"), "0 0 * * * ?");

// Second, split on white-space. We expect six parts.
std::regex split{ R"#(^\s*(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$)#",
Expand Down
9 changes: 9 additions & 0 deletions test/CronDataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,13 @@ SCENARIO("Replacing text with numbers")
std::string s = "JAN-DEC";
REQUIRE(CronData::replace_string_name_with_numeric<libcron::Months>(s) == "1-12");
}
}

SCENARIO("Parsing @ expressions works") {
REQUIRE(CronData::create("@yearly").is_valid());
REQUIRE(CronData::create("@annually").is_valid());
REQUIRE(CronData::create("@monthly").is_valid());
REQUIRE(CronData::create("@weekly").is_valid());
REQUIRE(CronData::create("@daily").is_valid());
REQUIRE(CronData::create("@hourly").is_valid());
}