Fix train timestamps

pull/3/head
Stijn De Clercq 2020-10-23 16:34:02 +02:00
parent c8946fdc49
commit f6c324d656
3 changed files with 7 additions and 7 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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}