Skip to content

Commit 4e98335

Browse files
author
Ilya Volodarsky
committed
fixing total_seconds python 2.6 compat issue and bump version
1 parent 536c4ef commit 4e98335

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

analytics/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ def is_naive(dt):
77
""" Determines if a given datetime.datetime is naive. """
88
return dt.tzinfo is None or dt.tzinfo.utcoffset(dt) is None
99

10+
def total_seconds(delta):
11+
""" Determines total seconds with python < 2.7 compat """
12+
# http://stackoverflow.com/questions/3694835/python-2-6-5-divide-timedelta-with-timedelta
13+
return (delta.microseconds + (delta.seconds + delta.days * 24 * 3600) * 1e6) / 1e6
1014

1115
def guess_timezone(dt):
1216
""" Attempts to convert a naive datetime to an aware datetime """
@@ -15,7 +19,7 @@ def guess_timezone(dt):
1519
# case, and then defaults to utc
1620

1721
delta = datetime.now() - dt
18-
if delta.total_seconds() < 5:
22+
if total_seconds(delta) < 5:
1923
# this was created using datetime.datetime.now()
2024
# so we are in the local timezone
2125
return dt.replace(tzinfo=tzlocal())

analytics/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '0.4.3'
1+
VERSION = '0.4.4'

history.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
0.4.3 / 2013-11-13
1+
0.4.4 / November 21, 2013
2+
------------------
3+
* add < python 2.7 compatibility by removing `delta.total_seconds`
4+
5+
0.4.3 / November 13, 2013
26
------------------
37
* added datetime serialization fix (alexlouden)
48

5-
0.4.2 / 2013-06-25
9+
0.4.2 / June 26, 2013
610
------------------
711
* Added history.d change log
812
* Merging https://github.com/segmentio/analytics-python/pull/14 to add support for lists and PEP8 fixes. Thanks https://github.com/dfee!

0 commit comments

Comments
 (0)