From c2f37b7e453b735cca11b40e28207a9eb8d5baf1 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Fri, 11 Nov 2022 23:21:41 +0500 Subject: [PATCH] News now properly handles date strings --- extra_widgets.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/extra_widgets.py b/extra_widgets.py index 2403811..09e6cb3 100644 --- a/extra_widgets.py +++ b/extra_widgets.py @@ -302,9 +302,18 @@ class NewsBlurb(QtWidgets.QWidget): pass 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 abs(eta) // 86400 >= 1: - self.NewsBlurbRelTimer.setText(f'{"Starts in " if eta // 86400 > 0 else ""}{abs(eta) // 86400}d') + if self.news_info.get('startDate'): + eta = round(time.mktime(time.strptime(self.news_info.get('startDate'), '%Y-%m-%dT%H:%M:%S.%fZ')) - time.time() + utcoffset) + 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: - 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')