import datetime
import re
import sys

import inflect

date_regex = re.compile(r"\d{4}-\d{2}-\d{2}")
p = inflect.engine()


def main():
  today = datetime.date.today()
  users_date = input("Date of Birth: ")
  try:
    users_date = parse_date(users_date)
  except ValueError:
    sys.exit(1)
  minutes = get_minutes(users_date, today)
  print(format_minutes(minutes))


def get_minutes(start_date, end_date):
  minutes = (end_date - start_date).total_seconds() / 60
  return int(round(minutes, 0))


def format_minutes(minutes: int) -> str:
  stringed_number = p.number_to_words(minutes, andword="").capitalize()
  return f"{stringed_number} minute{'s' if minutes > 1 else ''}"


def parse_date(date_string):
  if not date_regex.match(date_string):  # Acutally not necessary: strptime would raise ValueError anyway
    raise ValueError
  return datetime.datetime.strptime(date_string, '%Y-%m-%d').date()


if __name__ == '__main__':
  main()
