Skip to content

Commit

Permalink
Merge pull request beetbox#2367 from beetbox/timestamp-36
Browse files Browse the repository at this point in the history
Use a new stdlib method for dbcore.query._to_epoch_time on Python 3
  • Loading branch information
sampsyo authored Jan 2, 2017
2 parents 4711bf7 + 3acd448 commit 2fcde98
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions beets/dbcore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,13 @@ def _to_epoch_time(date):
"""Convert a `datetime` object to an integer number of seconds since
the (local) Unix epoch.
"""
epoch = datetime.fromtimestamp(0)
delta = date - epoch
return int(delta.total_seconds())
if hasattr(date, 'timestamp'):
# The `timestamp` method exists on Python 3.3+.
return int(date.timestamp())
else:
epoch = datetime.fromtimestamp(0)
delta = date - epoch
return int(delta.total_seconds())


def _parse_periods(pattern):
Expand Down

0 comments on commit 2fcde98

Please sign in to comment.