From f6c324d656b942769a7920c585bcc27d11f1101a Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Fri, 23 Oct 2020 16:34:02 +0200 Subject: [PATCH] Fix train timestamps --- cogs/corona.py | 4 ++-- cogs/train.py | 4 ++-- functions/timeFormatters.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cogs/corona.py b/cogs/corona.py index 64c4d4c..3ff6b51 100644 --- a/cogs/corona.py +++ b/cogs/corona.py @@ -94,7 +94,7 @@ class Corona(commands.Cog): inline=False) # Timestamp of last update - timeFormatted = timeFormatters.epochToDate(dic["today"]["updated"]) + timeFormatted = timeFormatters.epochToDate(int(dic["today"]["updated"])/1000) embed.set_footer(text="Laatst geüpdatet op {} ({} geleden)".format( timeFormatted["date"], timeFormatted["timeAgo"])) await ctx.send(embed=embed) @@ -146,7 +146,7 @@ class Corona(commands.Cog): distribution[0], distribution[1], distribution[2]), inline=False) # Timestamp of last update - timeFormatted = timeFormatters.epochToDate(dic["today"]["updated"]) + timeFormatted = timeFormatters.epochToDate(int(dic["today"]["updated"])/1000) embed.set_footer(text="Laatst geüpdatet op {} ({} geleden)".format( timeFormatted["date"], timeFormatted["timeAgo"])) await ctx.send(embed=embed) diff --git a/cogs/train.py b/cogs/train.py index f0b8011..7a4ebb6 100644 --- a/cogs/train.py +++ b/cogs/train.py @@ -4,7 +4,7 @@ from decorators import help import discord from discord.ext import commands, menus from enums.help_categories import Category -from functions import checks +from functions import checks, timeFormatters import requests @@ -69,7 +69,7 @@ class Train(commands.Cog): return str(minutes) + "m" return "{}h{:02}m".format(minutes // 60, minutes % 60) else: - return datetime.datetime.fromtimestamp(int(timestamp)).strftime("%H:%M") + return timeFormatters.epochToDate(int(timestamp), "%H:%M")["date"] def formatDelay(self, seconds): seconds = int(seconds) diff --git a/functions/timeFormatters.py b/functions/timeFormatters.py index 7f4b940..4e9801f 100644 --- a/functions/timeFormatters.py +++ b/functions/timeFormatters.py @@ -5,11 +5,11 @@ import dateutil.relativedelta import pytz -def epochToDate(epochTimeStamp): +def epochToDate(epochTimeStamp, strFormat="%m/%d/%Y om %H:%M:%S"): now = dateTimeNow() - updateTime = datetime.datetime.fromtimestamp(int(epochTimeStamp) / 1000, pytz.timezone("Europe/Brussels")) + updateTime = datetime.datetime.fromtimestamp(int(epochTimeStamp), pytz.timezone("Europe/Brussels")) diff = now - updateTime - updateFormatted = str(updateTime.strftime('%m/%d/%Y om %H:%M:%S')) + updateFormatted = str(updateTime.strftime(strFormat)) timeAgo = str(time.strftime('%H:%M:%S', time.gmtime(diff.total_seconds()))) return {"date": updateFormatted, "timeAgo": timeAgo}