'Field method to reduce case event date/time to just date,
used in pivot table reports to group case events by day'

def case_event_date_day(self, row):

    if hasattr(row, 'dvr_case_event'):
        row = row.dvr_case_event
    try:
        date = row.date
    except AttributeError:
        date = None
    if date:
        date = date.replace(tzinfo=self.UTC).astimezone(self.LOCAL)
        hour = date.time().hour
        date = date.date()
        if (hour <= 7):
            return (date - datetime.timedelta(days=1))
    else:
        date = None
    return date
