input: Write a python function to parse a date from a string.
  assert parse_date('2021-12-01') == '2021-12-01'
  assert parse_date('01/12/2021') == '2021-12-01'
  assert parse_date('12/01/2021', dayfirst=True) == '2021-12-01'
output: def parse_date(date_str, dayfirst=False):
      from datetime import datetime
      
      if '-' in date_str:
          date = datetime.strptime(date_str, '%Y-%m-%d')
      elif '/' in date_str:
          date_format = '%d/%m/%Y' if dayfirst else '%m/%d/%Y'
          date = datetime.strptime(date_str, date_format)
      else:
          raise ValueError('Unknown date format')
          
      return date.strftime('%Y-%m-%d')