parameters: (sString)
return_statement: return (cSeconds, None if not asErrors else ' '.join(asErrors))
docstring: Reverse of formatIntervalSeconds.
  
      Returns (cSeconds, sError), where sError is None on success.
docstring_summary: Reverse of formatIntervalSeconds.
docstring_tokens: Reverse of formatIntervalSeconds .
function: def parseIntervalSeconds(sString):
      """
      Reverse of formatIntervalSeconds.
  
      Returns (cSeconds, sError), where sError is None on success.
      """
  
      # We might given non-strings, just return them without any fuss.
      if not isString(sString):
          if isinstance(sString, (int, long)) or sString is None:
              return (sString, None);
          ## @todo time/date objects?
          return (int(sString), None);
  
      # Strip it and make sure it's not empty.
      sString = sString.strip();
      if not sString:
          return (0, 'Empty interval string.');
  
      #
      # Split up the input into a list of 'valueN, unitN, ...'.
      #
      # Don't want to spend too much time trying to make re.split do exactly what
      # I need here, so please forgive the extra pass I'm making here.
      #
      asRawParts = re.split(r'\s*([0-9]+)\s*([^0-9,;]*)[\s,;]*', sString);
      asParts    = [];
      for sPart in asRawParts:
          sPart = sPart.strip();
          if sPart:
              asParts.append(sPart);
      if not asParts:
          return (0, 'Empty interval string or something?');
  
      #
      # Process them one or two at the time.
      #
      cSeconds   = 0;
      asErrors   = [];
      i          = 0;
      while i < len(asParts):
          sNumber = asParts[i];
          i += 1;
          if sNumber.isdigit():
              iNumber = int(sNumber);
  
              sUnit = 's';
              if i < len(asParts) and not asParts[i].isdigit():
                  sUnit = asParts[i];
                  i += 1;
  
              sUnitLower = sUnit.lower();
              if sUnitLower in [ 's', 'se', 'sec', 'second', 'seconds' ]:
                  pass;
              elif sUnitLower in [ 'm', 'mi', 'min', 'minute', 'minutes' ]:
                  iNumber *= 60;
              elif sUnitLower in [ 'h', 'ho', 'hou', 'hour', 'hours' ]:
                  iNumber *= 3600;
              elif sUnitLower in [ 'd', 'da', 'day', 'days' ]:
                  iNumber *= 86400;
              elif sUnitLower in [ 'w', 'week', 'weeks' ]:
                  iNumber *= 7 * 86400;
              else:
                  asErrors.append('Unknown unit "%s".' % (sUnit,));
              cSeconds += iNumber;
          else:
              asErrors.append('Bad number "%s".' % (sNumber,));
      return (cSeconds, None if not asErrors else ' '.join(asErrors));
function_tokens: def parseIntervalSeconds ( sString ) : # We might given non-strings, just return them without any fuss. if not isString ( sString ) : if isinstance ( sString , ( int , long ) ) or sString is None : return ( sString , None ) ## @todo time/date objects? return ( int ( sString ) , None ) # Strip it and make sure it's not empty. sString = sString . strip ( ) if not sString : return ( 0 , 'Empty interval string.' ) # # Split up the input into a list of 'valueN, unitN, ...'. # # Don't want to spend too much time trying to make re.split do exactly what # I need here, so please forgive the extra pass I'm making here. # asRawParts = re . split ( r'\s*([0-9]+)\s*([^0-9,;]*)[\s,;]*' , sString ) asParts = [ ] for sPart in asRawParts : sPart = sPart . strip ( ) if sPart : asParts . append ( sPart ) if not asParts : return ( 0 , 'Empty interval string or something?' ) # # Process them one or two at the time. # cSeconds = 0 asErrors = [ ] i = 0 while i < len ( asParts ) : sNumber = asParts [ i ] i += 1 if sNumber . isdigit ( ) : iNumber = int ( sNumber ) sUnit = 's' if i < len ( asParts ) and not asParts [ i ] . isdigit ( ) : sUnit = asParts [ i ] i += 1 sUnitLower = sUnit . lower ( ) if sUnitLower in [ 's' , 'se' , 'sec' , 'second' , 'seconds' ] : pass elif sUnitLower in [ 'm' , 'mi' , 'min' , 'minute' , 'minutes' ] : iNumber *= 60 elif sUnitLower in [ 'h' , 'ho' , 'hou' , 'hour' , 'hours' ] : iNumber *= 3600 elif sUnitLower in [ 'd' , 'da' , 'day' , 'days' ] : iNumber *= 86400 elif sUnitLower in [ 'w' , 'week' , 'weeks' ] : iNumber *= 7 * 86400 else : asErrors . append ( 'Unknown unit "%s".' % ( sUnit , ) ) cSeconds += iNumber else : asErrors . append ( 'Bad number "%s".' % ( sNumber , ) ) return ( cSeconds , None if not asErrors else ' ' . join ( asErrors ) )