Saturday, February 20, 2010

Re: strftime vs date

Until the cygwin-problem gets fixed, what do you think about:

function! DateLastDay(day)
let day = abs(a:day) % 7
let dir = a:day < 0 ? -1 : 1
let sday = 60 * 60 * 24 * dir
let time = localtime() + sday
while strftime('%w', time) != day
let time += sday
endwh
return strftime('%c', time)
endf

" date -d 'last sunday' you will get Feb 14 or
echo DateLastDay(-7)
" date -d 'next Tuesday' you will get Feb 23
echo DateLastDay(2)

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments: