
from datetime import datetime, timezone

DATE_FMT = '%Y-%m-%d'


def date_to_str(day):
    return day.strftime(DATE_FMT)


def str_to_date(s):
    return datetime.strptime(s, DATE_FMT).replace(tzinfo=timezone.utc)


from datetime import datetime, timezone

DATE_FMT = '%Y-%m-%d'


def date_to_str(day):
    return day.strftime(DATE_FMT)


def str_to_date(s, tz=None):
    ret = datetime.strptime(s, DATE_FMT)
    if tz:
        return tz.localize(ret)
    else:
        return ret

Support use of local timezones when parsing date strings
Support use of local timezones when parsing date strings

  
  from datetime import datetime, timezone
  
  DATE_FMT = '%Y-%m-%d'
  
  
  def date_to_str(day):
      return day.strftime(DATE_FMT)
  
  
- def str_to_date(s):
+ def str_to_date(s, tz=None):
-     return datetime.strptime(s, DATE_FMT).replace(tzinfo=timezone.utc)
+     ret = datetime.strptime(s, DATE_FMT)
+     if tz:
+         return tz.localize(ret)
+     else:
+         return ret
  
Support use of local timezones when parsing date strings
## Code Before:

from datetime import datetime, timezone

DATE_FMT = '%Y-%m-%d'


def date_to_str(day):
    return day.strftime(DATE_FMT)


def str_to_date(s):
    return datetime.strptime(s, DATE_FMT).replace(tzinfo=timezone.utc)

## Instruction:
Support use of local timezones when parsing date strings
## Code After:

from datetime import datetime, timezone

DATE_FMT = '%Y-%m-%d'


def date_to_str(day):
    return day.strftime(DATE_FMT)


def str_to_date(s, tz=None):
    ret = datetime.strptime(s, DATE_FMT)
    if tz:
        return tz.localize(ret)
    else:
        return ret
