display auction end times in local timezone

This commit is contained in:
Lynne Megido 2020-08-28 18:16:52 +10:00
parent 59fcaae36a
commit aeb015568e
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
2 changed files with 17 additions and 8 deletions

View file

@ -198,7 +198,7 @@ class BuypeebApp:
self.items.set(treeIter, 0, item.name if item.name is not None else "")
if item.ready:
listing[1], listing[2], listing[3] = item.price_jpy(), item.price_aud(), item.ending_at()
listing[1], listing[2], listing[3] = item.price_jpy(), item.price_aud(), item.ending_at(True)
else:
listing[0] = "Loading..." if item.name == "" else item.name
for i in range(1, 4):
@ -208,7 +208,7 @@ class BuypeebApp:
def updateListTimes(self):
for listing in self.items:
item = self.settings.watchlist[listing[4]]
listing[3] = item.ending_at()
listing[3] = item.ending_at(True)
def updateSidePane(self, id: str):
item = self.settings.watchlist[id]
@ -218,7 +218,7 @@ class BuypeebApp:
"YahooName": item.original_name,
"Price": item.price_jpy(),
"PriceAUD": item.price_aud(),
"Ending": item.ending_in(),
"Ending": item.ending_in(True),
"Bids": str(item.bids),
"BuyItNow": f"{item.price_jpy(win = True)} ({item.price_aud(win = True)})" if item.win_price not in [0, "0", None, ""] else "No",
"AutoExtension": "Yes" if item.auto_extension else "No",

View file

@ -6,6 +6,7 @@ from datetime import datetime, timezone, timedelta
import functions
JST = timezone(timedelta(hours = 9))
LOCALTIME = timezone(timedelta(hours = 10)) # TODO: allow for customisation
class YahooAuctionsItem:
"""
@ -60,7 +61,8 @@ class YahooAuctionsItem:
self.win_price = 0
self.original_name = ""
self.favourite = None
self.end_date = None
self.end_date = datetime.fromisoformat('1970-01-01').replace(tzinfo = JST)
self.start_date = datetime.fromisoformat('1970-01-01').replace(tzinfo = JST)
self.bids = 0
self.auto_extension = None
self.rate = 75.0
@ -136,14 +138,21 @@ class YahooAuctionsItem:
p = self.win_price
return f"${self.price / rate:.2f}"
def ending_in(self):
def end_date_local(self):
return self.end_date.astimezone(LOCALTIME)
def start_date_local(self):
return self.start_date.astimezone(LOCALTIME)
def ending_in(self, local = False):
return "heenlo"
def ending_at(self):
now = datetime.now()
def ending_at(self, local = False):
now = datetime.now(tz = LOCALTIME)
ndate = now.strftime("%d %b")
if self.end_date != None:
idate, itime = self.end_date.strftime("%d %b"), self.end_date.strftime("%H:%M")
ed = self.end_date_local() if local else self.end_date
idate, itime = ed.strftime("%d %b"), ed.strftime("%H:%M")
if idate == ndate:
return itime
else: