Skip to content

Commit 3be4352

Browse files
Check time based condition correctness
1 parent a065ce1 commit 3be4352

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎lib/i18n/strings.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
CLI_APP = "when"
1616
UI_APP_LABEL = "When Automation Tool"
1717
UI_APP_COPYRIGHT = "© 2023-2025 Francesco Garosi"
18-
UI_APP_VERSION = "1.12.1b6"
18+
UI_APP_VERSION = "1.12.1b7"
1919

2020
# other strings that should not be translated
2121
UI_WHENEVER = "Whenever"

‎lib/items/cond_time.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,19 @@ def load_checking(
265265
tab = CheckedTable(item, item_line)
266266
assert tab.get_str("type") == self.type
267267
# TODO: check resulting dicts using get_array_of_dict_check_keys_vs_values
268-
self.time_specifications = tab.get_list_of_dict(
269-
"time_specifications", mandatory=True
268+
tests = {
269+
"weekday": lambda x: x in _WEEKDAYS_TOML,
270+
"year": lambda y: isinstance(y, int) and 0 < y <= 9999, # year boundaries
271+
"month": lambda m: isinstance(m, int) and 1 <= m <= 12,
272+
"day": lambda d: isinstance(d, int) and 1 <= d <= 31,
273+
"hour": lambda h: isinstance(h, int) and 0 <= h < 24,
274+
"minute": lambda m: isinstance(m, int) and 0 <= m < 60,
275+
"second": lambda s: isinstance(s, int) and 0 <= s < 60,
276+
}
277+
self.time_specifications = tab.get_list_of_dict_check_keys_vs_values(
278+
"time_specifications",
279+
lambda k, v: k in tests and tests[k](v),
280+
mandatory=True,
270281
)
271282

272283
def as_table(self):

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "when"
3-
version = "1.12.1b6"
3+
version = "1.12.1b7"
44
description = "Interface for the **whenever** automation tool"
55
authors = ["Francesco Garosi <francesco.garosi@gmail.com>"]
66
license = 'BSD 3-Clause "New" or "Revised" License'

0 commit comments

Comments
 (0)