Skip to content

Commit b3dc385

Browse files
FactController: Fix start date picker modifying date twice (#674)
Previously, setting the `date` property would (in addition to setting the property itself and the `default_day` property of the dayline) also update the fact's start and end, moving those by the same delta as the date property was modified. However, this caused a problem when changing the start date using the date picker, since `on_start_date_changed()` would already update the fact's start and end and then also update the `date` property, which would then update the fact *again*, effectively applying the delta twice. This commit fixes this problem by changing the `date` setter to no longer update the fact. This means that the `date` property now only tracks the currently selected day of the dayline (and the UI as a whole), making the setter and getter a bit better matched. This also means that any changes to the fact's start and end must be done separately from modifying the `date` property. There are two places that currently update the `date` property: 1. The `on_start_date_changed()` method, which already updates the fact. 2. The `increment_date()`, which is changed by this commit to update the fact. Note that `increment_date()` now uses the `Fact.date` property setter to modify the fact, which mostly implements the same logic as the code that it replaces, except there is a small change in behavior when `fact.start` is `None`. However, that is a corner case that probably almost never occurs and has other problems, so this is left for a later refactor. This fixes #590.
1 parent a3c1840 commit b3dc385

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

src/hamster/edit_activity.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,8 @@ def date(self):
134134

135135
@date.setter
136136
def date(self, value):
137-
delta = value - self._date if self._date else None
138137
self._date = value
139138
self.cmdline.default_day = value
140-
if self.fact and delta:
141-
if self.fact.start_time:
142-
self.fact.start_time += delta
143-
if self.fact.end_time:
144-
self.fact.end_time += delta
145-
# self.update_fields() here would enter an infinite loop
146139

147140
def on_prev_day_clicked(self, button):
148141
self.increment_date(-1)
@@ -161,6 +154,7 @@ def get_widget(self, name):
161154
def increment_date(self, days):
162155
delta = dt.timedelta(days=days)
163156
self.date += delta
157+
self.fact.date = self.date
164158
self.update_fields()
165159

166160
def show(self):

0 commit comments

Comments
 (0)