happenings/utils/common.py
def clean_year_month(year, month, month_orig):
    """
    If 'month_orig', which is the month given in the url BEFORE any next/prev
    query strings have been applied, is out of range, sets month to the
    current month and returns an error message. Also Returns an error
    message if the year given is +/- 50 years from now.
    If 'month', which is the month given in the url AFTER any next/prev
    query strings have been applied, is out of range, adjusts it to be
    in range (by also adjusting the year).
    """
    error = False
    error_msg = "The date given was invalid."
    if month_orig not in xrange(1, 13) and month_orig is not None:
        month = now.month
        error = error_msg
    # This takes care of 'next' query strings making month > 12
    while month > 12:
        month -= 12
        year += 1
    # This takes care of 'prev' query strings making month < 1
    while month < 1:
        month += 12
        year -= 1
    year, month, error = _check_year(year, month, error, error_msg)
    return year, month, error
def clean_year_month(year, month, month_orig):
    """
    If 'month_orig', which is the month given in the url BEFORE any next/prev
    query strings have been applied, is out of range, sets month to the
    current month and returns an error message. Also Returns an error
    message if the year given is +/- 50 years from now.
    If 'month', which is the month given in the url AFTER any next/prev
    query strings have been applied, is out of range, adjusts it to be
    in range (by also adjusting the year).
    """
    error = False
    error_msg = "The date given was invalid."
    if month_orig not in xrange(1, 13) and month_orig is not None:
        month = now.month
        error = error_msg
    # This takes care of 'next' query strings making month > 12
    while month > 12:
        month -= 12
        year += 1
    # This takes care of 'prev' query strings making month < 1
    while month < 1:
        month += 12
        year -= 1
    year, month, error = _check_year(year, month, error, error_msg)
    return year, month, error
If 'month_orig', which is the month given in the url BEFORE any next/prev
    query strings have been applied, is out of range, sets month to the
    current month and returns an error message. Also Returns an error
    message if the year given is +/- 50 years from now.
    If 'month', which is the month given in the url AFTER any next/prev
    query strings have been applied, is out of range, adjusts it to be
    in range (by also adjusting the year).