OCR / app /extract_dates /validate_date.py
ShahzainHaider's picture
Upload folder using huggingface_hub
7bbae49
raw
history blame
591 Bytes
import re
from dateutil import parser
def find_smallest_date(dates):
parsed_dates = [parser.parse(date) for date in dates]
smallest_date = min(parsed_dates)
print(smallest_date.strftime('%d-%m-%Y'))
return smallest_date.strftime('%d-%m-%Y')
def validate_date(date_string):
patterns = [
r'^\d{2}/\d{2}/\d{4}$', # MM/DD/YYYY
r'^\d{2}-\d{2}-\d{4}$', # DD-MM-YYYY
r'^\d{2}.\d{2}.\d{4}$' # DD.MM.YYYY
]
for pattern in patterns:
if re.match(pattern, date_string):
return True, pattern
return False, pattern