diff options
| author | Bobby <[email protected]> | 2022-09-10 20:55:18 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-09-10 20:55:18 -0400 |
| commit | abf8d97800626e059fc8ae828bcb8b176eec0f5f (patch) | |
| tree | dd9fc3f72c42a45ee5f271088cf772358ab91a45 /src | |
| parent | 7b8661bd9ee0c7e88a68a3f8a5391f73a32138fa (diff) | |
| download | edify-abf8d97800626e059fc8ae828bcb8b176eec0f5f.tar.xz edify-abf8d97800626e059fc8ae828bcb8b176eec0f5f.zip | |
Added date pattern
Diffstat (limited to 'src')
| -rw-r--r-- | src/edify/library/__init__.py | 1 | ||||
| -rw-r--r-- | src/edify/library/date.py | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/edify/library/__init__.py b/src/edify/library/__init__.py index 6bf12a5..64c94e7 100644 --- a/src/edify/library/__init__.py +++ b/src/edify/library/__init__.py @@ -6,3 +6,4 @@ from .ip import ipv6 from .mail import email from .mail import email_rfc_5322 from .phone import phone_number +from .date import date, iso_date diff --git a/src/edify/library/date.py b/src/edify/library/date.py new file mode 100644 index 0000000..94b536b --- /dev/null +++ b/src/edify/library/date.py @@ -0,0 +1,34 @@ +import re + +date_pattern = "^[0-9]{1,2}\\/[0-9]{1,2}\\/[0-9]{4}$" +iso_date_pattern = "^(?:\\d{4})-(?:\\d{2})-(?:\\d{2})T(?:\\d{2}):(?:\\d{2}):(?:\\d{2}(?:\\.\\d*)?)(?:(?:-(?:\\d{2}):(?:\\d{2})|Z)?)$" # noqa + + +def date(date: str) -> bool: + """Checks if a string is a valid date. + + Args: + date (str): The string to check. + Returns: + bool: True if the string is a valid date, False otherwise. + """ + + if re.match(date_pattern, date): + return True + else: + return False + + +def iso_date(date: str) -> bool: + """Checks if a string is a valid ISO date. + + Args: + date (str): The string to check. + Returns: + bool: True if the string is a valid ISO date, False otherwise. + """ + + if re.match(iso_date_pattern, date): + return True + else: + return False |
