From 6e08aa269926dab83a1d6caa45881b6fb9b3e082 Mon Sep 17 00:00:00 2001 From: madsmpedersen <m@madsp.dk> Date: Fri, 4 Dec 2015 07:34:14 +0100 Subject: [PATCH] speed up to_unix --- wetb/gtsdf/unix_time.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wetb/gtsdf/unix_time.py b/wetb/gtsdf/unix_time.py index c51a1e43..e01d816e 100644 --- a/wetb/gtsdf/unix_time.py +++ b/wetb/gtsdf/unix_time.py @@ -1,8 +1,11 @@ from datetime import datetime, date import numpy as np +timestamp0 = datetime.utcfromtimestamp(0) def to_unix(dateTime): - return (dateTime - datetime.utcfromtimestamp(0)).total_seconds() + #return dateTime.timestamp() + 3600 + return (dateTime - timestamp0).total_seconds() + #return (dateTime - datetime.utcfromtimestamp(0)).total_seconds() def from_unix_old(sec): @@ -32,4 +35,4 @@ def from_unix(sec): if du not in day_dict: day_dict[du] = date.fromordinal(719163 + du).timetuple()[:3] y, m, d = zip(*[day_dict[d_] for d_ in d]) - return ([datetime(*ymdhmsu) for ymdhmsu in zip(y, m, d, H.tolist(), M.tolist(), S.tolist(), ms.tolist())]) \ No newline at end of file + return ([datetime(*ymdhmsu) for ymdhmsu in zip(y, m, d, H.tolist(), M.tolist(), S.tolist(), ms.tolist())]) -- GitLab