Skip to content

Commit

Permalink
Change string date to int date parsing
Browse files Browse the repository at this point in the history
Also update tests
  • Loading branch information
Famlam committed Aug 18, 2024
1 parent c27f70b commit 0a7f5d1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions plugins/Construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def node(self, data, tags):
end_date = False
if date:
end_date = date
elif "timestamp" in data:
end_date = datetime.datetime.strptime(data["timestamp"][0:10], "%Y-%m-%d") + self.date_limit
elif "timestamp" in data and data["timestamp"] > 0:
end_date = datetime.datetime.fromtimestamp(data["timestamp"]) + self.date_limit
else:
return

Expand Down Expand Up @@ -171,15 +171,18 @@ def test(self):
def test_timestamp(self):
tags = {"construction": "yes"}
for ts in ["2003-01-04", "1989-03-10"]:
self.check_err(self.p.node({"timestamp": ts}, tags), ts)
for ts in ["2078-01-04"]:
assert not self.p.node({"timestamp": ts}, tags), ts
ts_int = datetime.datetime.timestamp(datetime.datetime.strptime(ts,"%Y-%m-%d"))
self.check_err(self.p.node({"timestamp": ts_int}, tags), ts)
for ts in ["2078-01-04", str(datetime.datetime.today())[0:10]]:
ts_int = datetime.datetime.timestamp(datetime.datetime.strptime(ts,"%Y-%m-%d"))
assert not self.p.node({"timestamp": ts_int}, tags), ts
assert not self.p.node({"timestamp": 0}, tags)

def test_recall(self):
tags = {"construction": "yes"}
today = datetime.datetime.today()
td = datetime.timedelta(days=6 * 30)
for i in range(5, 10, 1):
e = self.p.node({"timestamp": (today - i*td).strftime("%Y-%m-%d")}, tags)
e = self.p.node({"timestamp": datetime.datetime.timestamp(today - i*td)}, tags)
self.check_err(e, i)
assert e["subclass"] == i - 5

0 comments on commit 0a7f5d1

Please sign in to comment.