Skip to content

Commit

Permalink
fix: Incrementing Duration #21
Browse files Browse the repository at this point in the history
When seconds or minutes are added or removed via the Edit View,
minutes and hours should be adjusted accordingly. That is, we should
never allow 62 seconds or -5 minutes or any similar nonsense to be
displayed and stored as such.
  • Loading branch information
CodeMouse92 committed Feb 21, 2022
1 parent 5841dfa commit ffb3565
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/timecard/interface/editview.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,32 @@ def load_item(cls, timestamp):
cls.entry = TimeLog.retrieve_from_log(timestamp)
cls.refresh()

@classmethod
def normalize(cls):
hour = cls.spn_hour.value()
min = cls.spn_min.value()
sec = cls.spn_sec.value()

print(hour, min, sec)

if sec > 60:
min += sec // 60
sec %= 60
if min > 60:
hour += min // 60
min %= 60

print(hour, min, sec)

cls.spn_hour.setValue(hour)
cls.spn_min.setValue(min)
cls.spn_sec.setValue(sec)

@classmethod
def edited(cls):
# Normalize times
cls.normalize()
# Change interface to allow saving or reverting.
cls.btn_done.setEnabled(False)
cls.btn_revert.setEnabled(True)
cls.btn_save.setEnabled(True)
Expand Down

0 comments on commit ffb3565

Please sign in to comment.