code: def _valid_date(self):
          
          date = self._parse_date(self.date)
  
          if not date:
              exit_after_echo(INVALID_DATE)
  
          try:
              date = datetime.strptime(date, '%Y%m%d')
          except ValueError:
              exit_after_echo(INVALID_DATE)
  
          # A valid query date should within 50 days.
          offset = date - datetime.today()
          if offset.days not in range(-1, 50):
              exit_after_echo(INVALID_DATE)
  
          return datetime.strftime(date, '%Y-%m-%d')
docs: Check and return a valid query date.