Skip to content

Commit

Permalink
Fix datetime behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Dec 24, 2023
1 parent 2867824 commit 55214e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions errands/widgets/components/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 10 additions & 3 deletions errands/widgets/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 55214e4

Please sign in to comment.