Check if our system time change. If so, change our

        :return: 0 if the difference < 900, difference else
        :rtype: int
341287
def check_for_system_time_change(self):  # pragma: no cover, hardly testable with unit tests...
        
        now = time.time()
        difference = now - self.t_each_loop

        # Now set the new value for the tick loop
        self.t_each_loop = now

        # If we have more than 15 min time change, we need to compensate it
        # todo: confirm that 15 minutes is a good choice...
        if abs(difference) > 900:  # pragma: no cover, not with unit tests...
            return difference

        return 0
1325756
def diff(self, dt=None, abs=True):
        
        if dt is None:
            dt = self.now(self.tz)

        return Period(self, dt, absolute=abs)
13724
def dst(self):
        

        if self.tzinfo is None:
            return None
        return self.tzinfo.dst(self.replace(year=2000))
569547
def modification_time(self):
    """"""
    if self._stat_info is None:
      return None

    timestamp = int(self._stat_info.st_mtime)
    return dfdatetime_posix_time.PosixTime(timestamp=timestamp)
977587
def utcoffset(self):
        

        if self.tzinfo is None:
            return None
        return self.tzinfo.utcoffset(self.replace(year=2000))
463565
def hz
      now = Time.now
      @started_at ||= now
      diff = now - @started_at
      diff = 1 if diff == 0
      @cycle / diff
    end
385289
def check_time(value):
    """"""
    try:
        h, m = value.split(':')
        h = int(h)
        m = int(m)
        if h >= 24 or h < 0:
            raise ValueError
        if m >= 60 or m < 0:
            raise ValueError
    except ValueError:
        raise TimeDefinitionError("Invalid definition of time %r" % value)
660233
def I(self):
    "'"
    if self.timezone and self.timezone.dst(self.data):
      return u'1'
    else:
      return u'0'
744955
def dst(self, dt):
        
        if self.__is_daylight_time(dt):
            return self.__dst_offset - self.__offset
        else:
            return datetime.timedelta(0)
227910
def mkchange(text0,text1,version,mtime):
  ""
  return Change(version,mtime,ucrc(text1),diff.word_diff(text0,text1))
68191
def compensate_system_time_change(self, difference):  # pragma: no cover,
        # pylint: disable=too-many-branches
        # not with unit tests
        
        super(Alignak, self).compensate_system_time_change(difference)

        # We only need to change some value
        self.program_start = max(0, self.program_start + difference)

        if not hasattr(self.sched, "conf"):
            # Race condition where time change before getting conf
            return

        # Then we compensate all host/services
        for host in self.sched.hosts:
            host.compensate_system_time_change(difference)
        for serv in self.sched.services:
            serv.compensate_system_time_change(difference)

        # Now all checks and actions
        for chk in list(self.sched.checks.values()):
            # Already launch checks should not be touch
            if chk.status == u'scheduled' and chk.t_to_go is not None:
                t_to_go = chk.t_to_go
                ref = self.sched.find_item_by_id(chk.ref)
                new_t = max(0, t_to_go + difference)
                timeperiod = self.sched.timeperiods[ref.check_period]
                if timeperiod is not None:
                    # But it's no so simple, we must match the timeperiod
                    new_t = timeperiod.get_next_valid_time_from_t(new_t)
                # But maybe no there is no more new value! Not good :(
                # Say as error, with error output
                if new_t is None:
                    chk.state = u'waitconsume'
                    chk.exit_status = 2
                    chk.output = '(Error: there is no available check time after time change!)'
                    chk.check_time = time.time()
                    chk.execution_time = 0
                else:
                    chk.t_to_go = new_t
                    ref.next_chk = new_t

        # Now all checks and actions
        for act in list(self.sched.actions.values()):
            # Already launch checks should not be touch
            if act.status == u'scheduled':
                t_to_go = act.t_to_go

                #  Event handler do not have ref
                ref_id = getattr(act, 'ref', None)
                new_t = max(0, t_to_go + difference)

                # Notification should be check with notification_period
                if act.is_a == u'notification':
                    ref = self.sched.find_item_by_id(ref_id)
                    if ref.notification_period:
                        # But it's no so simple, we must match the timeperiod
                        notification_period = self.sched.timeperiods[ref.notification_period]
                        new_t = notification_period.get_next_valid_time_from_t(new_t)
                    # And got a creation_time variable too
                    act.creation_time += difference

                # But maybe no there is no more new value! Not good :(
                # Say as error, with error output
                if new_t is None:
                    act.state = 'waitconsume'
                    act.exit_status = 2
                    act.output = '(Error: there is no available check time after time change!)'
                    act.check_time = time.time()
                    act.execution_time = 0
                else:
                    act.t_to_go = new_t
1277216
def average(self, dt=None):
        
        if dt is None:
            dt = self.now(self.tz)

        diff = self.diff(dt, False)
        return self.add(
            microseconds=(diff.in_seconds() * 1000000 + diff.microseconds) // 2
        )
1042037
def hours(self,local=False):
        
        delta = self.delta(local)
        return delta.total_seconds()/3600
337581
def st_ctime(self):
        """"""
        ctime = self._st_ctime_ns / 1e9
        return ctime if self.use_float else int(ctime)
1130140
def idle_task(self):
        ''''''
        now = time.time()

        if now-self.last_sent > self.system_time_settings.interval:
            self.last_sent = now
            time_us = time.time() * 1000000
            if self.system_time_settings.verbose:
                print("ST: Sending system time: (%u/%u)" %
                      (time_us, self.uptime(),))
            self.master.mav.system_time_send(time_us,
                                             self.uptime())

        if (now-self.last_sent_timesync >
            self.system_time_settings.interval_timesync):
            self.last_sent_timesync = now
            time_ns = time.time() * 1000000000
            time_ns += 1234
            if self.system_time_settings.verbose:
                print("ST: Sending timesync request")
            self.master.mav.timesync_send(0, time_ns)
            self.last_sent_ts1 = time_ns
973618
def datetime(self):
        
        try:
            dt = self._tick_dict['datetime']
        except (KeyError, ValueError):
            return datetime.datetime.min
        else:
            if not isinstance(dt, datetime.datetime):
                if dt > 10000000000000000:  # ms
                    return convert_ms_int_to_datetime(dt)
                else:
                    return convert_int_to_datetime(dt)
            return dt
452214
def check(self):
    

    if self.value is None:
      return False
    return (time.clock() - self.start) >= self.value