'Compensate a system time change of difference for all hosts/services/checks/notifs'

def compensate_system_time_change(self, difference):

    logger.warning('A    system    time    change    of    %d    has    been    detected.    Compensating...', difference)
    self.program_start = max(0, (self.program_start + difference))
    if (not hasattr(self.sched, 'conf')):
        return
    for h in self.sched.hosts:
        h.compensate_system_time_change(difference)
    for s in self.sched.services:
        s.compensate_system_time_change(difference)
    for c in self.sched.checks.values():
        if ((c.status == 'scheduled') and (c.t_to_go is not None)):
            t_to_go = c.t_to_go
            ref = c.ref
            new_t = max(0, (t_to_go + difference))
            if (ref.check_period is not None):
                new_t = ref.check_period.get_next_valid_time_from_t(new_t)
            if (new_t is None):
                c.state = 'waitconsume'
                c.exit_status = 2
                c.output = '(Error:    there    is    no    available    check    time    after    time    change!)'
                c.check_time = time.time()
                c.execution_time = 0
            else:
                c.t_to_go = new_t
                ref.next_chk = new_t
    for c in self.sched.actions.values():
        if (c.status == 'scheduled'):
            t_to_go = c.t_to_go
            ref = getattr(c, 'ref', None)
            new_t = max(0, (t_to_go + difference))
            if (c.is_a == 'notification'):
                if ref.notification_period:
                    new_t = ref.notification_period.get_next_valid_time_from_t(new_t)
                c.creation_time = (c.creation_time + difference)
            if (new_t is None):
                c.state = 'waitconsume'
                c.exit_status = 2
                c.output = '(Error:    there    is    no    available    check    time    after    time    change!)'
                c.check_time = time.time()
                c.execution_time = 0
            else:
                c.t_to_go = new_t
