mirror of
https://github.com/osmarks/autobotrobot
synced 2025-01-24 14:16:52 +00:00
fortnight support
This commit is contained in:
parent
1f77fb9c1f
commit
6ad622e027
@ -27,6 +27,7 @@ number = "(-?[0-9]+(?:\.[0-9]+)?)(" + "|".join(prefixes.keys()) + ")?"
|
||||
short_timedelta_regex = re.compile(f"""
|
||||
(?:(?P<years>{number})(?:years?|y))? # e.g. 2y
|
||||
(?:(?P<months>{number})(?:months?|mo))? # e.g. 2months
|
||||
(?:(?P<fortnights>{number})(?:fortnights?|fn|f))? # e.g. 10fn
|
||||
(?:(?P<weeks>{number})(?:weeks?|w))? # e.g. 10w
|
||||
(?:(?P<days>{number})(?:days?|d))? # e.g. 14d
|
||||
(?:(?P<hours>{number})(?:hours?|h))? # e.g. 12h
|
||||
@ -45,6 +46,8 @@ def parse_short_timedelta(text):
|
||||
match = short_timedelta_regex.fullmatch(text)
|
||||
if match is None or not match.group(0): raise ValueError("parse failed")
|
||||
data = { k: parse_prefixed(v) if v else 0 for k, v in match.groupdict().items() }
|
||||
data["weeks"] += data["fortnights"] * 2
|
||||
del data["fortnights"]
|
||||
return datetime.datetime.now(tz=datetime.timezone.utc) + relativedelta(**data)
|
||||
|
||||
cal = parsedatetime.Calendar()
|
||||
|
Loading…
Reference in New Issue
Block a user