1
0
mirror of https://github.com/PerMalmberg/libcron.git synced 2025-10-18 05:45:20 -05:00

fixed convenience scheduling (#47)

This commit is contained in:
Philemon Benner
2025-10-10 16:14:27 +02:00
committed by GitHub
parent de143e8b8e
commit 8c144b0ddb
3 changed files with 21 additions and 12 deletions

View File

@@ -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

View File

@@ -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*$)#",

View File

@@ -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());
}