def METHOD_NAME(value):
    try:
        if str(int(value)) == value:
            return int(value) * 1000
    except ValueError:
        pass
    if not isinstance(value, str):
        return value
    if not value:
        return 0
    match = TimestampField.match_string.match(value)
    if not match:
        raise ValueError('Not a valid timestamp: ' + value)
    h, m, s, ms = match.groups()
    s = int(s)
    m = int(m or s / 60)
    s %= 60
    h = int(h or m / 60)
    m %= 60
    if ms:
        ln = len(ms)
        ms = int(ms)
        while ln < 3:
            ln += 1
            ms *= 10
    else:
        ms = 0
    return h * 3600000 + m * 60000 + s * 1000 + ms