Skip to content

Commit

Permalink
fix: handling of zero duration time entries (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau authored Jan 18, 2022
1 parent 1b98e1d commit d2bd9cb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions toggl/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def get_duration(name, instance): # type: (str, base.Entity) -> int
"""
Getter for Duration Property field.
Handles correctly the conversion of of negative running duration (for more refer to the Toggl API doc).
Handles correctly the conversion of negative running duration (for more refer to the Toggl API doc).
"""
if instance.is_running:
return instance.start.int_timestamp * -1
Expand All @@ -523,6 +523,8 @@ def set_duration(name, instance, value, init=False): # type: (str, base.Entity,
if value > 0:
instance.is_running = False
instance.stop = instance.start + pendulum.duration(seconds=value)
elif value == 0:
instance.is_running = False
else:
instance.is_running = True
instance.stop = None
Expand Down Expand Up @@ -572,7 +574,7 @@ def build_list_url(self, caller, config, conditions): # type: (str, utils.Confi

return url

def current(self, config=None): # type: (utils.Config) -> TimeEntry
def current(self, config=None): # type: (utils.Config) -> typing.Optional[TimeEntry]
"""
Method that returns currently running TimeEntry or None if there is no currently running time entry.
Expand Down

0 comments on commit d2bd9cb

Please sign in to comment.