summaryrefslogtreecommitdiff
path: root/python/skytools/timeutil.py
diff options
context:
space:
mode:
authormartinko2013-08-09 14:03:34 +0000
committermartinko2013-08-09 14:03:34 +0000
commit49ac8090682a5d76b577eeade3e29c9e4d83650c (patch)
tree0bd7141f24ccaa9cdaf2120006263bfe47d4f36a /python/skytools/timeutil.py
parentaae5c5b1dde3e456189cdff0fa1cd7b5cb369aa8 (diff)
parent344d063d4e61bdd382d9e1977964fa1fe6363991 (diff)
Merge branch 'release/skytools_3_1_5'skytools_3_1_5
Diffstat (limited to 'python/skytools/timeutil.py')
-rw-r--r--python/skytools/timeutil.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/python/skytools/timeutil.py b/python/skytools/timeutil.py
index a29e050c..2ea63082 100644
--- a/python/skytools/timeutil.py
+++ b/python/skytools/timeutil.py
@@ -134,18 +134,24 @@ def datetime_to_timestamp(dt, local_time=True):
Returns seconds since epoch as float.
- >>> datetime_to_timestamp(parse_iso_timestamp("2005-06-01 15:00:59.33 +02"))
- 1117630859.33
- >>> datetime_to_timestamp(datetime.fromtimestamp(1117630859.33, UTC))
- 1117630859.33
- >>> datetime_to_timestamp(datetime.fromtimestamp(1117630859.33))
- 1117630859.33
+ >>> datetime_to_timestamp(parse_iso_timestamp("2005-06-01 15:00:59.5 +02"))
+ 1117630859.5
+ >>> datetime_to_timestamp(datetime.fromtimestamp(1117630859.5, UTC))
+ 1117630859.5
+ >>> datetime_to_timestamp(datetime.fromtimestamp(1117630859.5))
+ 1117630859.5
>>> now = datetime.utcnow()
>>> now2 = datetime.utcfromtimestamp(datetime_to_timestamp(now, False))
+ >>> abs(now2.microsecond - now.microsecond) < 100
+ True
+ >>> now2 = now2.replace(microsecond = now.microsecond)
>>> now == now2
True
>>> now = datetime.now()
>>> now2 = datetime.fromtimestamp(datetime_to_timestamp(now))
+ >>> abs(now2.microsecond - now.microsecond) < 100
+ True
+ >>> now2 = now2.replace(microsecond = now.microsecond)
>>> now == now2
True
"""