Skip to content

Commit 6ba5765

Browse files
committed
custom validators
1 parent d2e2729 commit 6ba5765

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

dateandtimeparser/_validators.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def _datetime_format_type_validator(instance, attribute, value):
2+
if value != None and not isinstance(value, list):
3+
raise ValueError(
4+
"datetime_format attribute can be of type 'list' or 'None'.")
5+
6+
7+
def _mode_type_validator(instance, attribute, value):
8+
if value not in ["date", "datetime", "time"]:
9+
raise ValueError(
10+
"mode attribute's format can be of type 'date', 'time' or 'datetime'.")
11+
12+
13+
def _end_year_validator(instance, attribute, value):
14+
if value < instance.start_year:
15+
raise ValueError(
16+
"'end_year' has to be greater than or equal to 'start_year'!")

0 commit comments

Comments
 (0)