Skip to content

Commit ec76ec0

Browse files
authored
Merge pull request #19 from grumBit/Allow-LW-in-day-of-month.-Allow-mixed-case-for-months-and-days-
Allow LW in day of month. Allow mixed case for months and days.
2 parents 4e67b6a + 3875a70 commit ec76ec0

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313

1414
Validates these [AWS EventBridge cron expressions](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html#eb-cron-expressions), which are similar to, but not compatible with Unix style cron expressions;
1515

16-
| Field | Values | Wildcards |
17-
| :----------: | :-------------: | :-----------: |
18-
| Minute | 0-59 | , - * / |
19-
| Hour | 0-23 | , - * / |
20-
| Day-of-month | 1-31 | , - * ? / L W |
21-
| Month | 1-12 or JAN-DEC | , - * / |
22-
| Day-of-week | 1-7 or SUN-SAT | , - * ? L # |
23-
| Year | 1970-2199 | , - * / |
16+
| Field | Values | Wildcards |
17+
| :----------- | :-------------- | :------------- |
18+
| Minute | 0-59 | , - \* / |
19+
| Hour | 0-23 | , - \* / |
20+
| Day-of-month | 1-31 | , - \* ? / L W |
21+
| Month | 1-12 or JAN-DEC | , - \* / |
22+
| Day-of-week | 1-7 or SUN-SAT | , - \* ? L # |
23+
| Year | 1970-2199 | , - \* / |
24+
25+
_NB: It appears AWS is supporting the Quartz Job Scheduler cron expressions. More details than AWS provides is available in the [Cron Trigger Tutorial](http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html)._
2426

2527
This was inspired by Niloy Chakraborty's [AWSCronValidator.py](https://gist.github.com/ultrasonex/e1fdb8354408a56df91aa4902d17aa6a) project.
2628

RELEASENOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release History
22

3+
### v1.1.10 [2024-02-01]
4+
5+
- Fixes;
6+
- [Doesn't allow LW in day of month, or mixed case for months and days](https://github.com/grumBit/aws_cron_expression_validator/issues/18)
7+
38
### v1.1.9 [2024-02-01]
49

510
- Fixes;

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "aws_cron_expression_validator"
7-
version = "1.1.9"
7+
version = "1.1.10"
88
authors = [
99
{ name="Graham Coster", email="bitjugglers@gmail.com" },
1010
]

src/aws_cron_expression_validator/validator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class AWSCronExpressionValidator:
5151
minute_values = r"(0?[0-9]|[1-5][0-9])" # [0]0-59
5252
hour_values = r"(0?[0-9]|1[0-9]|2[0-3])" # [0]0-23
5353
month_of_day_values = r"(0?[1-9]|[1-2][0-9]|3[0-1])" # [0]1-31
54-
month_values = r"(0?[1-9]|1[0-2]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)" # [0]1-12 or JAN-DEC
55-
day_of_week_values = r"([1-7]|SUN|MON|TUE|WED|THU|FRI|SAT)" # 1-7 or SAT-SUN
54+
month_values = r"(?i)(0?[1-9]|1[0-2]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)" # [0]1-12 or JAN-DEC
55+
day_of_week_values = r"(?i)([1-7]|SUN|MON|TUE|WED|THU|FRI|SAT)" # 1-7 or SAT-SUN
5656
day_of_week_hash = rf"({day_of_week_values}#[1-5])" # Day of the week in the Nth week of the month
5757
year_values = r"((19[7-9][0-9])|(2[0-1][0-9][0-9]))" # 1970-2199
5858
natural_number = r"([0-9]*[1-9][0-9]*)" # Integers greater than 0
@@ -126,7 +126,8 @@ def hour_regex(cls) -> str:
126126
@classmethod
127127
def day_of_month_regex(cls) -> str:
128128
return (
129-
rf"^({cls.common_regex(cls.month_of_day_values)}|\?|L|{cls.month_of_day_values}W)$" # values , - * / ? L W
129+
rf"^({cls.common_regex(cls.month_of_day_values)}|\?|L|LW|{cls.month_of_day_values}W)$"
130+
# values , - * / ? L W
130131
)
131132

132133
@classmethod

tests/aws_cron_expression_validator/test_validator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_hour_regex(self):
9494

9595
def test_day_of_month_regex(self):
9696
given_regex = validator.AWSCronExpressionValidator.day_of_month_regex()
97-
given_valid_matches = ["*", "1", "01", "10", "23", "31", "?", "L", "1W", "31W", "11W"]
97+
given_valid_matches = ["*", "1", "01", "10", "23", "31", "?", "L", "1W", "31W", "11W", "LW"]
9898
given_invalid_matches = [
9999
"0",
100100
"32",
@@ -121,15 +121,15 @@ def test_day_of_month_regex(self):
121121
def test_month_regex(self):
122122
given_regex = validator.AWSCronExpressionValidator.month_regex()
123123

124-
given_valid_matches = ["*", "1", "01", "10", "12", "JAN", "FEB", "DEC", "JAN-MAR", "02-MAR", "*-MAR", "FEB/2"]
124+
given_valid_matches = ["*", "1", "01", "10", "12", "JAN", "feb", "DeC", "JAN-MAR", "02-MAR", "*-MAR", "FEB/2"]
125125
given_invalid_matches = ["0", "13", "600", "-1", "XZY", "JANUARY", "", "2/FEB", "?", "L", "W", "#"]
126126

127127
self._then_matches(given_regex, given_valid_matches)
128128
self._then_does_not_match(given_regex, given_invalid_matches)
129129

130130
def test_day_of_week_regex(self):
131131
given_regex = validator.AWSCronExpressionValidator.day_of_week_regex()
132-
given_valid_matches = ["*", "1", "5", "7", "MON", "?", "L", "5L", "MONL", "3#2", "MON-FRI", "L-1", "L-7"]
132+
given_valid_matches = ["*", "1", "5", "7", "MON", "?", "L", "5L", "monL", "3#2", "MON-FRI", "L-1", "L-7"]
133133
given_invalid_matches = [
134134
"Monday",
135135
"0",
@@ -199,7 +199,7 @@ def test_validator(self):
199199
"0 10 * * ? *",
200200
"15 12 * * ? *",
201201
"0 8 1 * ? *",
202-
"1/5 8-17 ? * MON-FRI *",
202+
"1/5 8-17 ? * Mon-Fri *",
203203
"0 9 ? * 2#1 *",
204204
"0 07/12 ? * * *",
205205
"10,20,30,40 07/12 ? * * *",

0 commit comments

Comments
 (0)