Deriving day-of-week from YYYY-MM-DD date in vim script

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Deriving day-of-week from YYYY-MM-DD date in vim script

Marcin Komorowski
I have a script that need to convert date strings in the format of
YYYY-MM-DD to day-of-week, and I've been unable to find a way to do it.

If I had the date in localtime than I can use strftime("%a",localtime), but
there is no function to convert date string, i.e. 'YYYY-MM-DD' to localtime.

Any ideas?

Thanks,
Marcin


Reply | Threaded
Open this post in threaded view
|

Re: Deriving day-of-week from YYYY-MM-DD date in vim script

Charles E Campbell Jr
Marcin Komorowski wrote:

> I have a script that need to convert date strings in the format of
> YYYY-MM-DD to day-of-week, and I've been unable to find a way to do it.
>
> If I had the date in localtime than I can use
> strftime("%a",localtime), but there is no function to convert date
> string, i.e. 'YYYY-MM-DD' to localtime.


Hello!

My calutil.vim script has a vim function called DayOfWeek() - here's a
snippet...

" DayOfWeek: {{{1
" Usage :  call DayOfWeek(y,m,d,[0|1|2])
"   g:CalUtilDayOfWeek: if 0-> integer (default)
"                          1-> 3-letter English abbreviation for name of day
"                          2-> English name of day
" Returns
" g:CalUtilDayOfWeek
" ---------
"         1  :  0      1       2         3        4      5        6
"         2  : Mon    Tue     Wed       Thu      Fri    Sat      Sun
"       3  : Monday Tuesday Wednesday Thursday Friday Saturday Sunday
fun! DayOfWeek(y,m,d,...)


The numbers and days line up with a fixed-width font.

Its available at my website:
http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs
as "Calendar Utilities".

Regards,
Chip Campbell