Skip to content

Commit

Permalink
Added 5 minute interval align for time select buttons (#415)
Browse files Browse the repository at this point in the history
* added 5 minute interval align for time select buttons

* fixed linting error

* fixed formatting error

* fixed formatting
  • Loading branch information
danielhass authored Oct 26, 2023
1 parent 45ba173 commit ec075d5
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions timetagger/app/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,18 @@ def _get_time(self, what, fallback=True):
hh, mm, ss = utils.timestr2tuple(self["ori_" + what])
return hh, mm, ss

def _stepwise_delta(self, mm, delta):
if delta >= 0:
# delta is positiv, apply modulo with offset
return delta - (mm % delta)
else:
# delta is negative
mm_new = -(mm % -(delta))
if mm_new == 0:
# we are already at stepsize, just return delta
return delta
return mm_new

def render(self):
now = dt.now()

Expand Down Expand Up @@ -919,6 +931,9 @@ def render(self):
self.date2input.style.color = None

def onchanged(self, action):
# step size used for time buttons
_stepsize = 5

now = dt.now()

# Get node
Expand Down Expand Up @@ -986,9 +1001,9 @@ def onchanged(self, action):
else:
hh, mm, ss = self._get_time("time1")
if option == "more":
mm, ss = mm + 5, 0
mm, ss = mm + self._stepwise_delta(mm, _stepsize), 0
elif option == "less":
mm, ss = mm - 5, 0
mm, ss = mm + self._stepwise_delta(mm, -(_stepsize)), 0
d1 = window.Date(year1, month1 - 1, day1, hh, mm, ss)
self.t1 = dt.to_time_int(d1)
if self.ori_t1 == self.ori_t2:
Expand All @@ -1008,9 +1023,9 @@ def onchanged(self, action):
else:
hh, mm, ss = self._get_time("time2")
if option == "more":
mm, ss = mm + 5, 0
mm, ss = mm + self._stepwise_delta(mm, _stepsize), 0
elif option == "less":
mm, ss = mm - 5, 0
mm, ss = mm + self._stepwise_delta(mm, -(_stepsize)), 0
d2 = window.Date(year2, month2 - 1, day2, hh, mm, ss)
self.t2 = dt.to_time_int(d2)
if self.ori_t1 == self.ori_t2:
Expand Down

0 comments on commit ec075d5

Please sign in to comment.