code: def get_expire_time(cache_duration=None, valid_until=None):
          
          expire_time = None
  
          if cache_duration is not None:
              expire_time = OneLogin_Saml2_Utils.parse_duration(cache_duration)
  
          if valid_until is not None:
              if isinstance(valid_until, int):
                  valid_until_time = valid_until
              else:
                  valid_until_time = OneLogin_Saml2_Utils.parse_SAML_to_time(valid_until)
              if expire_time is None or expire_time > valid_until_time:
                  expire_time = valid_until_time
  
          if expire_time is not None:
              return '%d' % expire_time
          return None
docs: Compares 2 dates and returns the earliest.
  
          :param cache_duration: The duration, as a string.
          :type: string
  
          :param valid_until: The valid until date, as a string or as a timestamp
          :type: string
  
          :return: The expiration time.
          :rtype: int