Skip to content

Commit 8c144b0

Browse files
fixed convenience scheduling (#47)
1 parent de143e8 commit 8c144b0

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ These special time specification tokens which replace the 5 initial time and dat
210210

211211
|Token|Meaning
212212
| --- | --- |
213-
| @yearly | Run once a year, ie. "0 0 1 1 *".
214-
| @annually | Run once a year, ie. "0 0 1 1 *".
215-
| @monthly | Run once a month, ie. "0 0 1 * *".
216-
| @weekly | Run once a week, ie. "0 0 * * 0".
217-
| @daily | Run once a day, ie. "0 0 * * *".
218-
| @hourly | Run once an hour, ie. "0 * * * *".
213+
| @yearly | Run once a year, ie. "0 0 0 1 1 *".
214+
| @annually | Run once a year, ie. "0 0 0 1 1 *"".
215+
| @monthly | Run once a month, ie. "0 0 0 1 * *".
216+
| @weekly | Run once a week, ie. "0 0 0 * * 0".
217+
| @daily | Run once a day, ie. "0 0 0 * * ?".
218+
| @hourly | Run once an hour, ie. "0 0 * * * ?".
219219

220220
# Randomization
221221

libcron/src/CronData.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ namespace libcron
3939
{
4040
// First, check for "convenience scheduling" using @yearly, @annually,
4141
// @monthly, @weekly, @daily or @hourly.
42-
std::string tmp = std::regex_replace(cron_expression, std::regex("@yearly"), "0 0 1 1 *");
43-
tmp = std::regex_replace(tmp, std::regex("@annually"), "0 0 1 1 *");
44-
tmp = std::regex_replace(tmp, std::regex("@monthly"), "0 0 1 * *");
45-
tmp = std::regex_replace(tmp, std::regex("@weekly"), "0 0 * * 0");
46-
tmp = std::regex_replace(tmp, std::regex("@daily"), "0 0 * * *");
47-
const std::string expression = std::regex_replace(tmp, std::regex("@hourly"), "0 * * * *");
42+
std::string tmp = std::regex_replace(cron_expression, std::regex("@yearly"), "0 0 0 1 1 *");
43+
tmp = std::regex_replace(tmp, std::regex("@annually"), "0 0 0 1 1 *");
44+
tmp = std::regex_replace(tmp, std::regex("@monthly"), "0 0 0 1 * *");
45+
tmp = std::regex_replace(tmp, std::regex("@weekly"), "0 0 0 * * 0");
46+
tmp = std::regex_replace(tmp, std::regex("@daily"), "0 0 0 * * ?");
47+
const std::string expression = std::regex_replace(tmp, std::regex("@hourly"), "0 0 * * * ?");
4848

4949
// Second, split on white-space. We expect six parts.
5050
std::regex split{ R"#(^\s*(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$)#",

test/CronDataTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,13 @@ SCENARIO("Replacing text with numbers")
237237
std::string s = "JAN-DEC";
238238
REQUIRE(CronData::replace_string_name_with_numeric<libcron::Months>(s) == "1-12");
239239
}
240+
}
241+
242+
SCENARIO("Parsing @ expressions works") {
243+
REQUIRE(CronData::create("@yearly").is_valid());
244+
REQUIRE(CronData::create("@annually").is_valid());
245+
REQUIRE(CronData::create("@monthly").is_valid());
246+
REQUIRE(CronData::create("@weekly").is_valid());
247+
REQUIRE(CronData::create("@daily").is_valid());
248+
REQUIRE(CronData::create("@hourly").is_valid());
240249
}

0 commit comments

Comments
 (0)