import re


def date_format(date, format_as="dash"):
    """
    Util function for formatting season dates as required  by the sportsreference module. Dashed format for a season is the regular way its written, eg "2018-19". Single format only contains the second year of the NBA Season, i.e for the 2018-19 season the single date format is simply 2019
    :param date: Date to be formatted
    :type date: String or Integer
    :param format_as:
    :type: format_as: "dash" or "single"
    """

    if format_as== "dash":
        if re.match("^\d{4}-\d\d", str(date)):
            return date
        else:
            second_year = str(date)[-2:]
            return str(int(date) - 1) + "-" + str(second_year)
    elif format_as == "single":
        if re.match("^\d{4}-\d\d", str(date)):
            return str(int(date[:4]) + 1)
        else:
            return date