(self)
Opening hours: hour_from and hour_to are given within event TZ or UTC.
        Now() must therefore be computed based on that TZ.
Opening hours: hour_from and hour_to are given within event TZ or UTC.
        Now() must therefore be computed based on that TZ.
Opening hours : hour_from and hour_to are given within event TZ or UTC . Now () must therefore be computed based on that TZ .
def _compute_is_in_opening_hours(self):
        """ Opening hours: hour_from and hour_to are given within event TZ or UTC.
        Now() must therefore be computed based on that TZ. """
        for sponsor in self:
            if not sponsor.event_id.is_ongoing:
                sponsor.is_in_opening_hours = False
            elif not sponsor.hour_from or not sponsor.hour_to:
                sponsor.is_in_opening_hours = True
            else:
                event_tz = timezone(sponsor.event_id.date_tz)
                # localize now, begin and end datetimes in event tz
                dt_begin = sponsor.event_id.date_begin.astimezone(event_tz)
                dt_end = sponsor.event_id.date_end.astimezone(event_tz)
                now_utc = utc.localize(fields.Datetime.now().replace(microsecond=0))
                now_tz = now_utc.astimezone(event_tz)

                # compute opening hours
                opening_from_tz = event_tz.localize(datetime.combine(now_tz.date(), float_to_time(sponsor.hour_from)))
                opening_to_tz = event_tz.localize(datetime.combine(now_tz.date(), float_to_time(sponsor.hour_to)))

                opening_from = max([dt_begin, opening_from_tz])
                opening_to = min([dt_end, opening_to_tz])

                sponsor.is_in_opening_hours = opening_from <= now_tz < opening_to
def _compute_is_in_opening_hours ( self ) : for sponsor in self : if not sponsor . event_id . is_ongoing : sponsor . is_in_opening_hours = False elif not sponsor . hour_from or not sponsor . hour_to : sponsor . is_in_opening_hours = True else : event_tz = timezone ( sponsor . event_id . date_tz ) # localize now, begin and end datetimes in event tz dt_begin = sponsor . event_id . date_begin . astimezone ( event_tz ) dt_end = sponsor . event_id . date_end . astimezone ( event_tz ) now_utc = utc . localize ( fields . Datetime . now ( ) . replace ( microsecond = 0 ) ) now_tz = now_utc . astimezone ( event_tz ) # compute opening hours opening_from_tz = event_tz . localize ( datetime . combine ( now_tz . date ( ) , float_to_time ( sponsor . hour_from ) ) ) opening_to_tz = event_tz . localize ( datetime . combine ( now_tz . date ( ) , float_to_time ( sponsor . hour_to ) ) ) opening_from = max ( [ dt_begin , opening_from_tz ] ) opening_to = min ( [ dt_end , opening_to_tz ] ) sponsor . is_in_opening_hours = opening_from <= now_tz < opening_to