Fix date/time fields which have nonsense negative values for any field
    except for year by rolling the overall date/time value backwards, treating
    negative values as relative offsets of the next higher unit.

    For example minute=5, second=-63 becomes minute=3, second=57 (5 minutes
    less 63 seconds)

    This is very unsophisticated handling of negative values which we would
    ideally do with `dateutil.relativedelta` but cannot because that class does
    not support arbitrary dates, especially not negative years which is the
    only case where these nonsense values are likely to occur anyway.

    NOTE: To greatly simplify the logic we assume all months are 30 days long.

def _roll_negative_time_fields(year, month, day, hour, minute, second):
    """
    Fix date/time fields which have nonsense negative values for any field
    except for year by rolling the overall date/time value backwards, treating
    negative values as relative offsets of the next higher unit.

    For example minute=5, second=-63 becomes minute=3, second=57 (5 minutes
    less 63 seconds)

    This is very unsophisticated handling of negative values which we would
    ideally do with `dateutil.relativedelta` but cannot because that class does
    not support arbitrary dates, especially not negative years which is the
    only case where these nonsense values are likely to occur anyway.

    NOTE: To greatly simplify the logic we assume all months are 30 days long.
    """
    if second < 0:
        minute += int(second / 60.0)  # Adjust by whole minute in secs
        minute -= 1  # Subtract 1 for negative second
        second %= 60  # Convert negative second to positive remainder
    if minute < 0:
        hour += int(minute / 60.0)  # Adjust by whole hour in minutes
        hour -= 1  # Subtract 1 for negative minutes
        minute %= 60  # Convert negative minute to positive remainder
    if hour < 0:
        day += int(hour / 24.0)  # Adjust by whole day in hours
        day -= 1  # Subtract 1 for negative minutes
        hour %= 24  # Convert negative hour to positive remainder
    if day < 0:
        month += int(day / 30.0)  # Adjust by whole month in days (assume 30)
        month -= 1  # Subtract 1 for negative minutes
        day %= 30  # Convert negative day to positive remainder
    if month < 0:
        year += int(month / 12.0)  # Adjust by whole year in months
        year -= 1  # Subtract 1 for negative minutes
        month %= 12  # Convert negative month to positive remainder
    return (year, month, day, hour, minute, second)