Parsing a date in VimScript

Given the date string of the form "2012-09-31", I need a vimscript function to parse it so that I can calculate relative dates. Pure vimscript or python solutions are welcome.

+4
source share
2 answers

What is it worth, here is my current solution. Offers the best deals or improvements.

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 
+2
source

For normal dates, there is an excellent SpeedDating plugin from Tim Papa. In principle, it should be possible to extract some of the internal functions of this plugin for use in other scenarios, but I do not know how easy it is in practice.

+1
source

Source: https://habr.com/ru/post/1433051/


All Articles