[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[emacs-wiki-discuss] Re: Thinking about planning
From: |
Stefan Reichör |
Subject: |
[emacs-wiki-discuss] Re: Thinking about planning |
Date: |
Fri, 09 Sep 2005 09:45:48 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
Hi Sacha!
> As I was trying to figure out how to do weekly planning, I realized I
> didn't know a nice, easy Emacs function for finding the current week
> number. Would anyone happen to have that handy? Alternatively, I could
> use something like Week.2005.09.05 to signify the week starting on
> 2005.09.05 (depending on calendar-week-start-day).
Here is my function to accomplish that task:
(defun calendar-week-number (date)
"Return the week number for DATE.
The week starts on MONDAY."
(let* ((year (extract-calendar-year date))
(day-number (calendar-day-number date))
(day-of-week-first-day (calendar-day-of-week (list 1 1 year)))
(adjust))
(when (eq 0 day-of-week-first-day)
(setq day-of-week-first-day 7))
(setq adjust (% (- 9 day-of-week-first-day) 8))
(if (< day-number adjust)
(calendar-week-number (list 12 31 (- year 1)))
(+ 1 (/ (- day-number adjust) 7)))))
It would be nice to integrate that function in emacs. What do you think?
And the following function bound to ?w, displays the week number for
the current date in the calendar:
(defun calendar-display-kw ()
(interactive)
(message "%s is in KW%d"
(calendar-date-string (calendar-cursor-to-date t))
(calendar-week-number (calendar-cursor-to-date t))))
(define-key calendar-mode-map "w" 'calendar-display-kw)
Stefan.