From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Last workday of the month Date: Sat, 30 Oct 2010 16:19:54 -0400 Message-ID: <6322.1288469994@gamaville.dokosmarshall.org> References: Reply-To: nicholas.dokos@hp.com Return-path: Received: from [140.186.70.92] (port=43674 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PCHuS-0007qN-MP for emacs-orgmode@gnu.org; Sat, 30 Oct 2010 16:20:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PCHuR-00058g-GV for emacs-orgmode@gnu.org; Sat, 30 Oct 2010 16:20:16 -0400 Received: from vms173019pub.verizon.net ([206.46.173.19]:34220) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PCHuR-00058T-D6 for emacs-orgmode@gnu.org; Sat, 30 Oct 2010 16:20:15 -0400 Received: from gamaville.dokosmarshall.org ([unknown] [173.76.32.106]) by vms173019.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0LB4003NHDT7R2L0@vms173019.mailsrvcs.net> for emacs-orgmode@gnu.org; Sat, 30 Oct 2010 15:19:55 -0500 (CDT) In-reply-to: Message from Chris Maier of "Sat, 30 Oct 2010 14:55:57 EDT." 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: Chris Maier Cc: nicholas.dokos@hp.com, emacs-orgmode@gnu.org 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. I've tried > to adapt the example given in the Emacs manual and this is what I came > up with: > > %%(let ((month (car date)) > (day (cadr date)) > (dayname (calendar-day-of-week date))) > (or > ;; months with 31 days > (and (memq month '(1 3 5 7 8 10 12)) > (or (and (= day 31) > (memq dayname '(1 2 3 4 5))) > (and (memq day '(29 30)) > (= dayname 5)))) > ;; months with 30 days > (and (memq month '(4 6 9 11)) > (or (and (= day 30) > (memq dayname '(1 2 3 4 5))) > (and (memq day '(28 29)) > (= dayname 5)))) > ;; February (the weird one) > (and (= month 2) > (or (and (memq day '(28 29)) > (memq dayname '(1 2 3 4 5))) > (and (memq day '(26 27 28)) > (= dayname 5)))))) Chris' Paycheck Deposited > > It appears to work so far. However, 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. Am 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)) (day (calendar-extract-day date)) (month (calendar-extract-month date)) (year (calendar-extract-year date)) (lastday (calendar-last-day-of-month month year)) (last-two-days-before-last-day (list (- lastday 2) (- lastday 1)))) (or (and (= day lastday) (memq dayname '(1 2 3 4 5))) (and (memq day last-two-days-before-last-day) (= dayname 5))) ) 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