Browse files

Raise TypeErrors for invalid argument types.

  • Loading branch information...
1 parent add60fd commit 0e670e140df102d461d803ada9508e314a204641 @jparise jparise committed Oct 26, 2012
Showing with 3 additions and 7 deletions.
  1. +3 −7 times/
10 times/
@@ -36,7 +36,7 @@ def to_universal(local_dt, timezone=None):
def from_local(local_dt, timezone=None):
"""Converts the given local datetime to a universal datetime."""
if not isinstance(local_dt, datetime.datetime):
- raise ValueError('First argument should be int, float or datetime.')
+ raise TypeError('Expected a datetime object')
if timezone is not None:
if local_dt.tzinfo is not None:
@@ -63,9 +63,7 @@ def from_unix(ut):
time. Assumes the input is in UTC, as `time.time()` does.
if not isinstance(ut, (int, float)):
- raise ValueError(
- 'First argument to from_unix should be an int or float'
- )
+ raise TypeError('Expected an int or float value')
return datetime.datetime.utcfromtimestamp(float(ut))
@@ -85,9 +83,7 @@ def to_local(dt, timezone):
def to_unix(dt):
"""Converts a datetime object to unixtime"""
if not isinstance(dt, datetime.datetime):
- raise ValueError(
- 'First argument to to_unix should be a datetime object'
- )
+ raise TypeError('Expected a datetime object')
return calendar.timegm(dt.utctimetuple())

0 comments on commit 0e670e1

Please sign in to comment.