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:
12
README.md
12
README.md
@@ -210,12 +210,12 @@ These special time specification tokens which replace the 5 initial time and dat
|
|||||||
|
|
||||||
|Token|Meaning
|
|Token|Meaning
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| @yearly | Run once a year, ie. "0 0 1 1 *".
|
| @yearly | Run once a year, ie. "0 0 0 1 1 *".
|
||||||
| @annually | Run once a year, ie. "0 0 1 1 *".
|
| @annually | Run once a year, ie. "0 0 0 1 1 *"".
|
||||||
| @monthly | Run once a month, ie. "0 0 1 * *".
|
| @monthly | Run once a month, ie. "0 0 0 1 * *".
|
||||||
| @weekly | Run once a week, ie. "0 0 * * 0".
|
| @weekly | Run once a week, ie. "0 0 0 * * 0".
|
||||||
| @daily | Run once a day, ie. "0 0 * * *".
|
| @daily | Run once a day, ie. "0 0 0 * * ?".
|
||||||
| @hourly | Run once an hour, ie. "0 * * * *".
|
| @hourly | Run once an hour, ie. "0 0 * * * ?".
|
||||||
|
|
||||||
# Randomization
|
# Randomization
|
||||||
|
|
||||||
|
@@ -39,12 +39,12 @@ namespace libcron
|
|||||||
{
|
{
|
||||||
// First, check for "convenience scheduling" using @yearly, @annually,
|
// First, check for "convenience scheduling" using @yearly, @annually,
|
||||||
// @monthly, @weekly, @daily or @hourly.
|
// @monthly, @weekly, @daily or @hourly.
|
||||||
std::string tmp = std::regex_replace(cron_expression, std::regex("@yearly"), "0 0 1 1 *");
|
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 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 1 * *");
|
tmp = std::regex_replace(tmp, std::regex("@monthly"), "0 0 0 1 * *");
|
||||||
tmp = std::regex_replace(tmp, std::regex("@weekly"), "0 0 * * 0");
|
tmp = std::regex_replace(tmp, std::regex("@weekly"), "0 0 0 * * 0");
|
||||||
tmp = std::regex_replace(tmp, std::regex("@daily"), "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 * * * *");
|
const std::string expression = std::regex_replace(tmp, std::regex("@hourly"), "0 0 * * * ?");
|
||||||
|
|
||||||
// Second, split on white-space. We expect six parts.
|
// Second, split on white-space. We expect six parts.
|
||||||
std::regex split{ R"#(^\s*(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$)#",
|
std::regex split{ R"#(^\s*(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$)#",
|
||||||
|
@@ -237,4 +237,13 @@ SCENARIO("Replacing text with numbers")
|
|||||||
std::string s = "JAN-DEC";
|
std::string s = "JAN-DEC";
|
||||||
REQUIRE(CronData::replace_string_name_with_numeric<libcron::Months>(s) == "1-12");
|
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());
|
||||||
}
|
}
|
Reference in New Issue
Block a user