mirror of
https://github.com/osmarks/autobotrobot
synced 2025-01-09 15:10:27 +00:00
fortnight support
This commit is contained in:
parent
1f77fb9c1f
commit
6ad622e027
17
src/util.py
17
src/util.py
@ -25,13 +25,14 @@ number = "(-?[0-9]+(?:\.[0-9]+)?)(" + "|".join(prefixes.keys()) + ")?"
|
|||||||
|
|
||||||
# from here: https://github.com/Rapptz/RoboDanny/blob/18b92ae2f53927aedebc25fb5eca02c8f6d7a874/cogs/utils/time.py
|
# from here: https://github.com/Rapptz/RoboDanny/blob/18b92ae2f53927aedebc25fb5eca02c8f6d7a874/cogs/utils/time.py
|
||||||
short_timedelta_regex = re.compile(f"""
|
short_timedelta_regex = re.compile(f"""
|
||||||
(?:(?P<years>{number})(?:years?|y))? # e.g. 2y
|
(?:(?P<years>{number})(?:years?|y))? # e.g. 2y
|
||||||
(?:(?P<months>{number})(?:months?|mo))? # e.g. 2months
|
(?:(?P<months>{number})(?:months?|mo))? # e.g. 2months
|
||||||
(?:(?P<weeks>{number})(?:weeks?|w))? # e.g. 10w
|
(?:(?P<fortnights>{number})(?:fortnights?|fn|f))? # e.g. 10fn
|
||||||
(?:(?P<days>{number})(?:days?|d))? # e.g. 14d
|
(?:(?P<weeks>{number})(?:weeks?|w))? # e.g. 10w
|
||||||
(?:(?P<hours>{number})(?:hours?|h))? # e.g. 12h
|
(?:(?P<days>{number})(?:days?|d))? # e.g. 14d
|
||||||
(?:(?P<minutes>{number})(?:minutes?|m))? # e.g. 10m
|
(?:(?P<hours>{number})(?:hours?|h))? # e.g. 12h
|
||||||
(?:(?P<seconds>{number})(?:seconds?|s))? # e.g. 15s """, re.VERBOSE)
|
(?:(?P<minutes>{number})(?:minutes?|m))? # e.g. 10m
|
||||||
|
(?:(?P<seconds>{number})(?:seconds?|s))? # e.g. 15s """, re.VERBOSE)
|
||||||
|
|
||||||
def parse_prefixed(s):
|
def parse_prefixed(s):
|
||||||
match = re.match(number, s)
|
match = re.match(number, s)
|
||||||
@ -45,6 +46,8 @@ def parse_short_timedelta(text):
|
|||||||
match = short_timedelta_regex.fullmatch(text)
|
match = short_timedelta_regex.fullmatch(text)
|
||||||
if match is None or not match.group(0): raise ValueError("parse failed")
|
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 = { 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)
|
return datetime.datetime.now(tz=datetime.timezone.utc) + relativedelta(**data)
|
||||||
|
|
||||||
cal = parsedatetime.Calendar()
|
cal = parsedatetime.Calendar()
|
||||||
|
Loading…
Reference in New Issue
Block a user