mirror of
https://github.com/beetbox/beets.git
synced 2026-02-01 13:03:59 +01:00
Merge pull request #2367 from beetbox/timestamp-36
Use a new stdlib method for dbcore.query._to_epoch_time on Python 3
This commit is contained in:
commit
2fcde98d4b
1 changed files with 7 additions and 3 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue