From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chris Maier Subject: Re: Last workday of the month Date: Sat, 30 Oct 2010 20:03:15 -0400 Message-ID: References: <6322.1288469994@gamaville.dokosmarshall.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=37313 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PCLOH-0000Qe-Iy for emacs-orgmode@gnu.org; Sat, 30 Oct 2010 20:03:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PCLOG-0007mi-GM for emacs-orgmode@gnu.org; Sat, 30 Oct 2010 20:03:17 -0400 Received: from mail-pv0-f169.google.com ([74.125.83.169]:44128) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PCLOG-0007me-9E for emacs-orgmode@gnu.org; Sat, 30 Oct 2010 20:03:16 -0400 Received: by pvc21 with SMTP id 21so506124pvc.0 for ; Sat, 30 Oct 2010 17:03:15 -0700 (PDT) In-Reply-To: <6322.1288469994@gamaville.dokosmarshall.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: nicholas.dokos@hp.com Cc: emacs-orgmode@gnu.org Where do the functions 'calendar-extract-day', 'calendar-extract-month', 'calendar-extract-year', and 'calendar-last-day-of-the-month' come from? I was looking for something like those when I wrote my initial implementation, but I don't seem to have them (hence the ugliness of the code!) I'm running GNU Emacs 23.2 for Mac OS X. Searching for these functions using `C-h f` turns up nothing for me. Thanks for the help, Chris On Sat, Oct 30, 2010 at 4:19 PM, Nick Dokos wrote: > Chris Maier wrote: > >> I'm trying to come up with a sexp diary entry that shows my payday, >> which is the last weekday of the month, in my Org agenda. =A0I've tried >> to adapt the example given in the Emacs manual and this is what I came >> up with: >> >> %%(let ((month (car date)) >> =A0 =A0 =A0 =A0 (day (cadr date)) >> =A0 =A0 =A0 =A0 (dayname (calendar-day-of-week date))) >> =A0 =A0 (or >> =A0 =A0 =A0;; months with 31 days >> =A0 =A0 =A0(and (memq month '(1 3 5 7 8 10 12)) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0(or (and (=3D day 31) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (memq dayname '(1 2 3 4 5))) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(and (memq day '(29 30)) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (=3D dayname 5)))) >> =A0 =A0 =A0;; months with 30 days >> =A0 =A0 =A0(and (memq month '(4 6 9 11)) >> =A0 =A0 =A0 =A0 =A0 (or (and (=3D day 30) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(memq dayname '(1 2 3 4 5))) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (and (memq day '(28 29)) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(=3D dayname 5)))) >> =A0 =A0 =A0;; February (the weird one) >> =A0 =A0 =A0(and (=3D month 2) >> =A0 =A0 =A0 =A0 =A0 (or (and (memq day '(28 29)) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(memq dayname '(1 2 3 4 5))) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (and (memq day '(26 27 28)) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(=3D dayname 5)))))) Chris' Paych= eck Deposited >> >> It appears to work so far. =A0However, I'm certain there's got to be a >> more concise way of coding this, but I can't seem to find any >> pre-existing calendar functions that might help. =A0Am I missing >> something? >> > > This is based on the same idea and example from the manual, but it > precalculates what it needs in order to simplify the decision at > the end: > > (let* ((dayname (calendar-day-of-week date)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0(day (calendar-extract-day date)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0(month (calendar-extract-month date)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0(year (calendar-extract-year date)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0(lastday (calendar-last-day-of-month month yea= r)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0(last-two-days-before-last-day (list (- lastda= y 2) (- lastday 1)))) > =A0 =A0 =A0 =A0 =A0 (or (and (=3D day lastday) (memq dayname '(1 2 3 4 5)= )) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 (and (memq day last-two-days-before-last-day)= (=3D dayname 5))) > =A0 =A0 =A0 =A0 =A0 =A0 =A0) > > Very lightly tested, so use with caution. > >> To make this even better, is there some way to consult another file of >> diary entries containing all the holidays at my workplace, so the >> diary entry would show up on the last weekday of the month that is not >> a company holiday? >> > > I'm sure there is - simplest is probably to set a variable in your > .emacs with all the holidays - schedule that with org for Dec. 31 :-) - > but you are on your own for that. I just don't think it's worth it: at > least for me, there are only three holidays during a year that might > interfere with that pay schedule. > > HTH, > Nick >