def get_season_bounds(input): """ Get the date bounds indicating a season's start and end. :param input: A year, date, or string indicating the current season. :return: DATETIME.DATE, DATETIME.DATE """ if type(input) == int: years = org_ncaa.get_season_years(input) elif type(input) == str: dt = datetime.strptime(input, '%m/%d/%Y') years = org_ncaa.get_season_years(org_ncaa.get_season(dt)) elif type(input) == datetime.date: years = org_ncaa.get_season_years(org_ncaa.get_season(input)) return datetime.date(years[0], 10, 30), datetime.date(years[1], 4, 30)
def get_date_bounds(input=None): """ Get the two dates that bound a time range specified by the input. Behavior: - If a year is specified then the dates that bound the season for that year will be returned. - If a date is specified, then the start date of the season in which that date occurs will be returned along with the specified date as the end date - If a string is specified, it will be converted to a date if possible, and then treated as a date input. :param input: A year, date, or string specifying the time range. :return: DATETIME.DATE, DATETIME.DATE """ if type(input) == str: # try to convert to date dt = datetime.datetime.strptime(input, '%m/%d/%Y').date() bounds = map(lambda d: d.strftime('%Y-%m-%d'), list(get_season_bounds(dt))) bounds = [bounds[0], dt.strftime('%Y-%m-%d')] elif isinstance(input, datetime.date): bounds = map(lambda d: d.strftime('%Y-%m-%d'), list(get_season_bounds(input))) bounds = [bounds[0], input.strftime('%Y-%m-%d')] elif type(input) == int and (input > 1900 and input <= org_ncaa.get_season(datetime.datetime.now())): bounds = map(lambda d: d.strftime('%Y-%m-%d'), list(get_season_bounds(input))) else: bounds = [datetime.date(1900, 10, 30), datetime.date(3000, 4, 30)] return bounds