code: def ensure_timezone(dt, tz=None):
      
      if dt.tzinfo is None:
          return dt.replace(tzinfo=tz or tzlocal())
      else:
          return dt
docs: Make sure the datetime <dt> has a timezone set, using timezone <tz> if it
      doesn't. <tz> defaults to the local timezone.