yandextank/common/util.py
def expand_time(str_time, default_unit='s', multiplier=1):
    """
    helper for above functions
    """
    parser = re.compile(r'(\d+)([a-zA-Z]*)')
    parts = parser.findall(str_time)
    result = 0.0
    for value, unit in parts:
        value = int(value)
        unit = unit.lower()
        if unit == '':
            unit = default_unit

        if unit == 'ms':
            result += value * 0.001
            continue
        elif unit == 's':
            result += value
            continue
        elif unit == 'm':
            result += value * 60
            continue
        elif unit == 'h':
            result += value * 60 * 60
            continue
        elif unit == 'd':
            result += value * 60 * 60 * 24
            continue
        elif unit == 'w':
            result += value * 60 * 60 * 24 * 7
            continue
        else:
            raise ValueError(
                "String contains unsupported unit %s: %s" % (unit, str_time))
    return int(result * multiplier)
def expand_time(str_time, default_unit='s', multiplier=1):
    parser = re.compile(r'(\d+)([a-zA-Z]*)')
    parts = parser.findall(str_time)
    result = 0.0
    for value, unit in parts:
        value = int(value)
        unit = unit.lower()
        if unit == '':
            unit = default_unit

        if unit == 'ms':
            result += value * 0.001
            continue
        elif unit == 's':
            result += value
            continue
        elif unit == 'm':
            result += value * 60
            continue
        elif unit == 'h':
            result += value * 60 * 60
            continue
        elif unit == 'd':
            result += value * 60 * 60 * 24
            continue
        elif unit == 'w':
            result += value * 60 * 60 * 24 * 7
            continue
        else:
            raise ValueError(
                "String contains unsupported unit %s: %s" % (unit, str_time))
    return int(result * multiplier)
def expand_time ( str_time , default_unit = 's' , multiplier = 1 ) : parser = re . compile ( r'(\d+)([a-zA-Z]*)' ) parts = parser . findall ( str_time ) result = 0.0 for value , unit in parts : value = int ( value ) unit = unit . lower ( ) if unit == '' : unit = default_unit if unit == 'ms' : result += value * 0.001 continue elif unit == 's' : result += value continue elif unit == 'm' : result += value * 60 continue elif unit == 'h' : result += value * 60 * 60 continue elif unit == 'd' : result += value * 60 * 60 * 24 continue elif unit == 'w' : result += value * 60 * 60 * 24 * 7 continue else : raise ValueError ( "String contains unsupported unit %s: %s" % ( unit , str_time ) ) return int ( result * multiplier )
helper for above functions
helper for above functions