Ejemplo n.º 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
            NetProfiler 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)
Ejemplo n.º 2
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
            NetProfiler 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)
Ejemplo n.º 3
0
    def __init__(self, start, end):
        if start is not None:
            self.start = timeutils.force_to_utc(start)
        else:
            self.start = 0

        if end is not None:
            self.end = timeutils.force_to_utc(end)
        else:
            self.end = 0
Ejemplo n.º 4
0
    def __init__(self, start, end):
        if start is not None:
            self.start = timeutils.force_to_utc(start)
        else:
            self.start = 0

        if end is not None:
            self.end = timeutils.force_to_utc(end)
        else:
            self.end = 0
Ejemplo n.º 5
0
 def __init__(self, start, end):
     self.start = force_to_utc(start)
     self.end = force_to_utc(end)
Ejemplo n.º 6
0
 def __init__(self, start, end):
     self.start = timeutils.force_to_utc(start)
     self.end = timeutils.force_to_utc(end)
Ejemplo n.º 7
0
 def c3datefmt(d):
     return '%s.%s' % (force_to_utc(d).strftime('%Y-%m-%dT%H:%M:%S'),
                       "%03dZ" % int(d.microsecond / 1000))
Ejemplo n.º 8
0
 def c3datefmt(d):
     return '%s.%s' % (force_to_utc(d).strftime('%Y-%m-%dT%H:%M:%S'),
                       "%03dZ" % int(d.microsecond / 1000))
Ejemplo n.º 9
0
 def __init__(self, start, end):
     self.start = force_to_utc(start)
     self.end = force_to_utc(end)