@@ -0,0 +1,2689 @@
+#!/usr/bin/env python%0A%0Aimport datetime%0A%0Aclass qtime(object):%0A    # Takes a time of either a datetime object or a string of format %22HH:MM%22%0A    # (in 24-hour time), and optionally an %22early%22 or %22late%22 value of the same%0A    # format, which simply substracts or adds to the time.%0A    # Given both an early and a late value, the time will be randomized within%0A    # the range created based on a hash of the current day so that comparisons%0A    # are consistent in the short term.%0A    def __init__(self, time, early=None, late=None):%0A        if isinstance(time, datetime.datetime):%0A            self.time = time%0A        elif isinstance(time, str):%0A            # Use the current time, but with the hour and minute replaced with%0A            # the given hour and minute.%0A            curtime = datetime.datetime.now()%0A            dtime = datetime.datetime.strptime(time, %22%25H:%25M%22)%0A            self.time = curtime.replace(hour=dtime.hour, minute=dtime.minute)%0A        else:%0A            raise TypeError(%22qtime() takes a datetime object or string of format '%25H:%25M'%22)%0A%0A        self.early = None%0A        if early != None:%0A            e = map(int, early.split(':'))%0A            self.early = datetime.timedelta(hours=e%5B0%5D, minutes=e%5B1%5D)%0A%0A        self.late = None%0A        if late != None:%0A            e = map(int, late.split(':'))%0A            self.late = datetime.timedelta(hours=e%5B0%5D, minutes=e%5B1%5D)%0A%0A    def __repr__(self):%0A        return %22qtime(%7B%7D, early=%7B%7D, late=%7B%7D)%22.format(repr(self.time), self.early, self.late)%0A%0A    # Returns the current time represented by this object, automatically taking%0A    # early and late values into account.%0A    def gettime(self):%0A        # If we have both an early value and a late value, randomize within the%0A        # period based on a hash of the current day so that comparisons are%0A        # consistent in the short term.%0A        if self.early != None and self.late != None:%0A            timerange = self.early + self.late%0A            datehash = abs(int(hash(datetime.datetime.now().date()))) # Today's %22random%22 number%0A            timerange_seconds = int(timerange.total_seconds())%0A            timerange_random = datehash %25 timerange_seconds # Get a %22random%22 value between 0 and timerange_seconds%0A            timerange_random_delta = datetime.timedelta(seconds=timerange_random)%0A            return self.time - self.early + timerange_random_delta%0A        elif self.early != None:%0A            return self.time - self.early%0A        elif self.late != None:%0A            return self.time + self.late%0A        else:%0A            return self.time%0A%0A    # Compare this QueryTime with a datetime object.%0A    def __cmp__(self, other):%0A        return cmp(self.gettime(), other.gettime())%0A

add qtime.py for calculating query times, including early/late