Given a date string of the form "2012-09-31", I'd like a vimscript function to parse it so I can calculate relative dates. Pure vimscript or python solutions are welcome.
For normal mode manipulation of dates there is the superb SpeedDating plugin from Tim Pope. In principle it should be possible to extract some of the internal functions of this plugin to use in other scripts, but I don't know how easy that is in practice.
For what it's worth, here's my current solution. Better suggestions or improvements are welcome.
function! AdjustDate(date, offset)
python << EOF
import vim
import datetime
result = datetime.datetime.strptime(vim.eval("a:date"), "%Y-%m-%d") + \
datetime.timedelta(days=int(vim.eval("a:offset")))
vim.command("let l:result = '" + result.strftime("%Y-%m-%d") + "'")
EOF
return result
endfunction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With