I’m doing a bit of programming here and there in Emacs Lisp, but I’m not entirely sure how to go about certain things.
I’m trying to insert a whole month of dates, each on a new line like the list below:
January
01/01/09 Mon:
02/01/09 Tue:
03/01/09 Wed:
etc
How would I go about doing that? I’ve found how to format dates, but I can’t find how to loop over a certain range of dates (in this instance to loop round a whole month and print a date for each day in the month).
Has anyone got some pointers they could give me on how to get started?
The functions you want are
'encode-time,'format-time-string, and'decode-time. For the proper documentation, eitherC-h f function-nameor will give you the documentation for the function, or the general elisp info pages can be found here:C-h i m elisp RET m time conversion RETHere’s that snippet:
I couldn’t find how to determine the number of days in a given month (sure, you could hard-code it, but then you’ve got to deal with leap years). Luckily,
'encode-timedoes all the addition for you, so if you pass it the equivalent of ‘February 31’, it’ll return ‘March 3’ (assuming 28 days).