Commits

Jason R. Coombs committed 168b92b

DelayedCommands now use the local time for calculating 'at' and 'due' times. This will be more friendly for simple servers. Servers that expect UTC times should either run in UTC or override DelayedCommand.now to return an appropriate time object for 'now'.

Comments (0)

Files changed (2)

+2.0
+===
+
+* DelayedCommands now use the local time for calculating 'at' and 'due'
+  times. This will be more friendly for simple servers. Servers that expect
+  UTC times should either run in UTC or override DelayedCommand.now to
+  return an appropriate time object for 'now'. For example::
+
+    def startup_bot():
+        irc.client.DelayedCommand.now = irc.client.DelayedCommand.utcnow
+        ...
+
 1.1
 ===
 
 class DelayedCommand(datetime.datetime):
     """
     A command to be executed after some delay (seconds or timedelta).
+
+    Clients may override .now() to have dates interpreted in a different
+    manner, such as to use UTC or to have timezone-aware times.
     """
     def __new__(cls, delay, function, arguments):
         if not isinstance(delay, datetime.timedelta):
             delay = datetime.timedelta(seconds=delay)
-        at = datetime.datetime.utcnow() + delay
+        at = cls.now() + delay
         cmd = datetime.datetime.__new__(DelayedCommand, at.year,
             at.month, at.day, at.hour, at.minute, at.second,
             at.microsecond, at.tzinfo)
     def at_time(cls, at, function, arguments):
         """
         Construct a DelayedCommand to come due at `at`, where `at` may be
-        a datetime or timestamp.
+        a datetime or timestamp. If `at` is a timestamp, it will be
+        interpreted as a naive local timestamp.
         """
         if isinstance(at, int):
-            at = datetime.datetime.utcfromtimestamp(at)
-        delay = at - datetime.datetime.utcnow()
+            at = datetime.datetime.fromtimestamp(at)
+        delay = at - cls.now()
         return cls(delay, function, arguments)
 
     def due(self):
-        return datetime.datetime.utcnow() >= self
+        return self.now() >= self
 
 class PeriodicCommand(DelayedCommand):
     """