From abf8d97800626e059fc8ae828bcb8b176eec0f5f Mon Sep 17 00:00:00 2001 From: Bobby Date: Sat, 10 Sep 2022 20:55:18 -0400 Subject: Added date pattern --- src/edify/library/__init__.py | 1 + src/edify/library/date.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/edify/library/date.py (limited to 'src') 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 -- cgit v1.2.3