Example #1
0
    def compare_time(self, t, resolution=60):
        """ Return True if time `t` falls in between start and end times.

            `t` may be a unix timestamp (float or string) or a datetime.datetime
            object

            `resolution` is the number of seconds to use for rounding.  Since
            Profiler stores data in one-minute increments, typically this
            should allow reasonable comparisons to report outputs.  Passing
            zero (`0`) in here will enforce strict comparisons.
        """
        # try converting to datetime object
        try:
            t = timeutils.string_to_datetime(t)
        except TypeError:
            pass

        # move everything to uniform utc timezone
        # string to datetime already returns utc, but if this is a
        # datetime object, we are just being safe here
        t = timeutils.force_to_utc(t)
        start = timeutils.force_to_utc(self.start)
        end = timeutils.force_to_utc(self.end)

        # by default, this will be one minute delta
        delta = datetime.timedelta(0, resolution, 0)
        return (start <= t <= end or
                abs(start - t) < delta or
                abs(end - t) < delta)
Example #2
0
    def __init__(self, start, end, gmtoffset=0):
        self.start = timeutils.force_to_utc(start)
        self.end = timeutils.force_to_utc(end)

        # XXX this was a legacy from v3 TimeFilters, get rid of it
        assert gmtoffset == 0