From 55214e4f46e16d231ba26b730953269b15314954 Mon Sep 17 00:00:00 2001 From: mrvladus Date: Sun, 24 Dec 2023 12:57:28 +0300 Subject: [PATCH] Fix datetime behavior --- errands/widgets/components/datetime.py | 3 +++ errands/widgets/details.py | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/errands/widgets/components/datetime.py b/errands/widgets/components/datetime.py index b4beecca..6465e02b 100644 --- a/errands/widgets/components/datetime.py +++ b/errands/widgets/components/datetime.py @@ -99,6 +99,9 @@ def get_human_datetime(self) -> str: out: str = _("Not Set") # type:ignore return out + def get_datetime_as_int(self) -> int: + return int(f"{self.datetime[:8]}{self.datetime[9:]}") if self.datetime else 0 + def set_datetime(self, dt: str): self.lock_signals = True if dt: diff --git a/errands/widgets/details.py b/errands/widgets/details.py index a312251e..dd2322fb 100644 --- a/errands/widgets/details.py +++ b/errands/widgets/details.py @@ -329,16 +329,23 @@ def on_save_btn_clicked(self, btn): # Sync Sync.sync() - def on_datetime_changed(self, dt): - pass - def on_start_time_changed(self, *args): Log.debug("Details: change start time") + sdt = self.start_datetime.get_datetime_as_int() + edt = self.end_datetime.get_datetime_as_int() + if sdt > edt and edt != 0: + self.end_datetime.set_datetime(self.start_datetime.get_datetime()) + self.end_datetime_row.set_title(self.end_datetime.get_human_datetime()) self.start_datetime_row.set_title(self.start_datetime.get_human_datetime()) self.save_btn.set_sensitive(True) def on_end_time_changed(self, *args): Log.debug("Details: change end time") + sdt = self.start_datetime.get_datetime_as_int() + edt = self.end_datetime.get_datetime_as_int() + if edt < sdt and sdt != 0 and edt != 0: + self.start_datetime.set_datetime(self.end_datetime.get_datetime()) + self.start_datetime_row.set_title(self.start_datetime.get_human_datetime()) self.end_datetime_row.set_title(self.end_datetime.get_human_datetime()) self.save_btn.set_sensitive(True)