Last active
July 10, 2021 12:00
-
-
Save wakita/2ae816e509b66c7710f8ed9b83e1f48e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# today | |
# today 1[d]: tomorrow, today 2[d]: the day after tomorrow | |
# today -1[d]: yesterday, today -2[d]: the day before yesterday | |
# today 1w: this day next week, 2w: two weeks later today, -2w: two weeks ago today | |
# today 1m: one month later today, 2m, -3m | |
# today 1y, -10y | |
snippet "today *(([+-]?[0-9]+)?)([dwmy]?)" "The date relative to today" r | |
`!p | |
import datetime | |
from dateutil.relativedelta import relativedelta | |
n = int(match.group(1) or '0') | |
k = match.group(3) or 'd' | |
key = next(key for key in 'days weeks months years'.split(' ') if key[0] == k) | |
delta = relativedelta(**dict([(key, n)])) | |
snip.rv = f"{(datetime.date.today() + delta).strftime('%Y-%m-%d')}"` | |
endsnippet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment