News now properly handles date strings

This commit is contained in:
Muaz Ahmad 2022-11-11 23:21:41 +05:00
parent 0530accb13
commit c2f37b7e45

View file

@ -302,9 +302,18 @@ class NewsBlurb(QtWidgets.QWidget):
pass pass
def update_timer(self): def update_timer(self):
eta = round(time.mktime(time.strptime(self.news_info['date'], '%Y-%m-%dT%H:%M:%S.%fZ')) - time.time() + utcoffset) if self.news_info.get('startDate'):
if abs(eta) // 86400 >= 1: eta = round(time.mktime(time.strptime(self.news_info.get('startDate'), '%Y-%m-%dT%H:%M:%S.%fZ')) - time.time() + utcoffset)
self.NewsBlurbRelTimer.setText(f'{"Starts in " if eta // 86400 > 0 else ""}{abs(eta) // 86400}d') prefix = 'Starts in '
if self.news_info.get('endDate'):
eta = round(time.mktime(time.strptime(self.news_info.get('endDate'), '%Y-%m-%dT%H:%M:%S.%fZ')) - time.time() + utcoffset)
prefix = 'Ends in '
if eta < 0:
prefix = ''
else: else:
self.NewsBlurbRelTimer.setText(f'{"Starts in " if eta > 0 else ""}{(abs(eta) // 3600) % 24}h {(abs(eta) // 60) % 60}m') eta = round(time.mktime(time.strptime(self.news_info.get('date'), '%Y-%m-%dT%H:%M:%S.%fZ')) - time.time() + utcoffset)
if abs(eta) // 86400 >= 1:
self.NewsBlurbRelTimer.setText(f'{prefix if eta // 86400 > 0 else ""}{abs(eta) // 86400}d')
else:
self.NewsBlurbRelTimer.setText(f'{prefix if eta > 0 else ""}{(abs(eta) // 3600) % 24}h {(abs(eta) // 60) % 60}m')