From 3e7374883cb003e91ada6a14b6f7fb0fc47be85d Mon Sep 17 00:00:00 2001 From: petya-vasileva Date: Fri, 10 Nov 2023 20:38:53 +0000 Subject: [PATCH] Fix date format --- utils/helpers.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/utils/helpers.py b/utils/helpers.py index 25dd691..b77daf0 100644 --- a/utils/helpers.py +++ b/utils/helpers.py @@ -59,24 +59,19 @@ def wrapper(dataframe): return wrapper -def convertTime(ts): - if pd.notnull(ts): - return datetime.utcfromtimestamp(ts/1000).strftime('%Y-%m-%d %H:%M') - - '''Returns a period of the past 3 hours''' def defaultTimeRange(hours=3): now = datetime.utcnow() - defaultEnd = datetime.strftime(now, '%Y-%m-%d %H:%M') + defaultEnd = datetime.strftime(now,"%Y-%m-%dT%H:%M:%S.000Z") defaultStart = datetime.strftime( - now - timedelta(hours=hours), '%Y-%m-%d %H:%M') + now - timedelta(hours=hours), "%Y-%m-%dT%H:%M:%S.000Z") return [defaultStart, defaultEnd] '''Finds the difference between two dates''' def FindPeriodDiff(dateFrom, dateTo): - fmt = '%Y-%m-%d %H:%M' + fmt = '%Y-%m-%dT%H:%M:%S.000Z' d1 = datetime.strptime(dateFrom, fmt) d2 = datetime.strptime(dateTo, fmt) time_delta = d2-d1 @@ -87,7 +82,7 @@ def FindPeriodDiff(dateFrom, dateTo): '''Splits the period into chunks of specified number of intervals.''' def GetTimeRanges(dateFrom, dateTo, intv=1): diff = FindPeriodDiff(dateFrom, dateTo) / intv - t_format = "%Y-%m-%d %H:%M" + t_format = '%Y-%m-%dT%H:%M:%S.000Z' tl = [] for i in range(intv+1): t = (datetime.strptime(dateFrom, t_format) + diff * i).strftime(t_format)