Index: datefmt.py
===================================================================
--- datefmt.py	(revision 5694)
+++ datefmt.py	(working copy)
@@ -31,8 +31,8 @@
 def pretty_timedelta(time1, time2=None, resolution=None):
     """Calculate time delta (inaccurately, only for decorative purposes ;-) for
     prettyprinting. If time1 is None, the current time is used."""
-    if not time1: time1 = datetime.now(utc)
-    if not time2: time2 = datetime.now(utc)
+    time1 = _normalize(time1)
+    time2 = _normalize(time2)
     if time1 > time2:
         time2, time1 = time1, time2
     units = ((3600 * 24 * 365, 'year',   'years'),
@@ -54,16 +54,21 @@
             return '%d %s' % (r, r == 1 and unit or unit_plural)
     return ''
 
+def _normalize(t, tzinfo = None):
+    if t is None:
+        return datetime.now(utc)
+    elif isinstance(t, (int,long,float)):
+        return datetime.fromtimestamp(t, tzinfo or localtz)
+    elif not isinstance(t,datetime):
+        raise TypeError, 'expecting datetime, int, long, float, or None; got %s' \
+              % type(t)
+    else:
+        return t
+    
 def format_datetime(t=None, format='%x %X', tzinfo=None):
-    if not tzinfo:
-        tzinfo = localtz
-    if t is None:
-        t = datetime.now(utc)
-    if isinstance(t, (int,long)):
-        t = datetime.fromtimestamp(t, tzinfo)
+    t = _normalize(t, tzinfo).astimezone(tzinfo or localtz)
     if format.lower() == 'iso8601':
         format = '%Y-%m-%dT%H:%M:%SZ%z'
-    t = t.astimezone(tzinfo)
     text = t.strftime(format)
     encoding = locale.getpreferredencoding() or sys.getdefaultencoding()
     if sys.platform != 'win32':
@@ -97,9 +102,7 @@
 
 def http_date(t=None):
     """Format t as a rfc822 timestamp"""
-    if t is None:
-        t = datetime.now(utc)
-    t = t.astimezone(utc)
+    t = _normalize(t).astimezone(utc)
     weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
     months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
               'Oct', 'Nov', 'Dec']

