You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2021/11/18 22:13:12 UTC
[incubator-ponymail-foal] 01/02: Add support for dfrom/dto
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
commit db5af7ae5725db9d77ea31d132cbb53477b210da
Author: Sebb <se...@apache.org>
AuthorDate: Thu Nov 18 22:01:30 2021 +0000
Add support for dfrom/dto
This relates to #110
---
server/plugins/defuzzer.py | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/server/plugins/defuzzer.py b/server/plugins/defuzzer.py
index 62ffb97..ca186f3 100644
--- a/server/plugins/defuzzer.py
+++ b/server/plugins/defuzzer.py
@@ -47,6 +47,23 @@ def defuzz(formdata: dict, nodate: bool = False, list_override: typing.Optional[
"gt": "%04u/%02u/01 00:00:00" % (int(syear), int(smonth)),
"lt": "%04u/%02u/%02u 23:59:59" % (int(eyear), int(emonth), eend),
}
+ # days ago to start, and number of days to match
+ elif "dfrom" in formdata and "dto" in formdata:
+ dfrom = formdata["dfrom"]
+ dto = formdata["dto"]
+ if re.match(r"\d+$", dfrom) and re.match(r"\d+$", dto):
+ ef = int(dfrom)
+ et = int(dto)
+ if ef > 0 and et > 0:
+ if et > ef:
+ et = ef # avoid overruning into the future
+ daterange = {
+ "gte": "now-%dd" % ef,
+ "lte": "now-%dd" % (ef - et),
+ }
+ else:
+ raise ValueError("Keywords 'dfrom' and 'dto' must be numeric")
+
# Advanced date formatting
elif "d" in formdata:
# The more/less than N days/weeks/months/years ago