def ver_date_cmp(ver1, date1, ver2, date2, ver_cmp):
    """
        Compare versions either by looking at the version string,
        or by looking at the release dates.
    """

    # if the package module provided a native compare function
    # then compare the version strings. This should be more
    # accurate and the preferred method.
    if ver_cmp:
        return ver_cmp(ver1, ver2)

    # No ver_cmp provided, e.g. Perl. fall back to
    # date comparison. Newer versions have more recent dates

    # consider date2 newer if date1 is None
    if date1 is None:
        return 1

    if date1 > date2:
        return 1

    if date1 < date2:
        return -1

    return 0