Skip to content

Commit

Permalink
ignore 0 end_time argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ederag committed Dec 11, 2019
1 parent 2e02dc5 commit 3c4c268
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/hamster-service
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,16 @@ class Storage(db.Storage, dbus.service.Object):
def AddFact(self, fact_str, start_time, end_time, temporary=False):
"""Add fact specified by a string.
For backward compatibility, if the resulting fact.start_time is None,
replace it with hamster_now().
Args:
fact_str (str): string to be parsed.
start_time (int): Start datetime timestamp.
Ignored if the value is 0.
For backward compatibility with the
gnome shell extension,
0 is special and means hamster_now().
Otherwise, overrides the parsed value.
-1 means None.
end_time (int): Start datetime timestamp.
Ignored if the value is 0.
Otherwise, overrides the parsed value.
If different from 0, overrides the parsed value.
-1 means None.
Returns:
fact id (int), or 0 in case of failure.
Expand All @@ -157,13 +155,17 @@ class Storage(db.Storage, dbus.service.Object):
"""
fact = Fact.parse(fact_str)

if start_time:
fact.start_time = None if start_time == -1 else dt.datetime.utcfromtimestamp(start_time)
if end_time:
fact.end_time = None if end_time == -1 else dt.datetime.utcfromtimestamp(end_time)
if start_time == -1:
fact.start_time = None
elif start_time == 0:
fact.start_time = stuff.hamster_now()
else:
fact.start_time = dt.datetime.utcfromtimestamp(start_time)

if not fact.start_time:
fact.start_time = hamster_now()
if end_time == -1:
fact.end_time = None
elif end_time != 0:
fact.end_time = dt.datetime.utcfromtimestamp(end_time)

return self.add_fact(fact) or 0

Expand Down

0 comments on commit 3c4c268

Please sign in to comment.