Skip to content

Commit

Permalink
Fix date format
Browse files Browse the repository at this point in the history
  • Loading branch information
petya-vasileva committed Nov 10, 2023
1 parent 8f6f2d2 commit 3e73748
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 3e73748

Please sign in to comment.