# Path: pq/utils/time.py
# def timedelta_seconds(delta):
#     return max(delta.total_seconds(), 0)


import time
from datetime import datetime, timedelta
from pulsar.utils.log import lazyproperty
from ..utils.time import timedelta_seconds
            times = int(timedelta_seconds(last_run_at - anchor) /
                        timedelta_seconds(run_every))
            if times:
                anchor += times * run_every
                while anchor <= last_run_at:
                    anchor += run_every
                while anchor > last_run_at:
                    anchor -= run_every
                self.anchor = anchor
            return anchor
        else:
            return last_run_at

    def next(self, now=None):
        '''Increase the :attr:`total_run_count` attribute by one and set the
        value of :attr:`last_run_at` to ``now``.
        '''
        self.last_run_at = now or datetime.now()
        self.total_run_count += 1

    def is_due(self, now=None):
        '''Returns tuple of two items ``(is_due, next_time_to_run)``,
        where next time to run is in seconds.

        See :meth:`unuk.contrib.tasks.models.PeriodicTask.is_due`
        for more information.
        '''
        last_run_at = self.scheduled_last_run_at
        now = now or datetime.now()
        rem_delta = last_run_at + self.run_every - now

# Path: pq/utils/time.py
# def timedelta_seconds(delta):
#     return max(delta.total_seconds(), 0)


# Path: pq/tasks/scheduler.py
import time
from datetime import datetime, timedelta
from pulsar.utils.log import lazyproperty
from ..utils.time import timedelta_seconds

            times = int(timedelta_seconds(last_run_at - anchor) /
                        timedelta_seconds(run_every))
            if times:
                anchor += times * run_every
                while anchor <= last_run_at:
                    anchor += run_every
                while anchor > last_run_at:
                    anchor -= run_every
                self.anchor = anchor
            return anchor
        else:
            return last_run_at

    def next(self, now=None):
        '''Increase the :attr:`total_run_count` attribute by one and set the
        value of :attr:`last_run_at` to ``now``.
        '''
        self.last_run_at = now or datetime.now()
        self.total_run_count += 1

    def is_due(self, now=None):
        '''Returns tuple of two items ``(is_due, next_time_to_run)``,
        where next time to run is in seconds.

        See :meth:`unuk.contrib.tasks.models.PeriodicTask.is_due`
        for more information.
        '''
        last_run_at = self.scheduled_last_run_at
        now = now or datetime.now()
        rem_delta = last_run_at + self.run_every - now

        rem = timedelta_seconds(rem_delta)