aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/edify/library/__init__.py1
-rw-r--r--src/edify/library/date.py34
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