From mboxrd@z Thu Jan 1 00:00:00 1970 From: Manish Subject: Re: Some useful timestamp s-expressions Date: Sat, 21 Aug 2010 22:56:33 +0530 Message-ID: References: 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=42734 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OmrqK-00042m-Pt for emacs-orgmode@gnu.org; Sat, 21 Aug 2010 13:26:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OmrqI-0002te-Lr for emacs-orgmode@gnu.org; Sat, 21 Aug 2010 13:26:56 -0400 Received: from mail-bw0-f41.google.com ([209.85.214.41]:63943) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OmrqI-0002tL-B1 for emacs-orgmode@gnu.org; Sat, 21 Aug 2010 13:26:54 -0400 Received: by bwz6 with SMTP id 6so3781132bwz.0 for ; Sat, 21 Aug 2010 10:26:53 -0700 (PDT) In-Reply-To: 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: Paul Sexton Cc: emacs-orgmode@gnu.org I added these to Worg. -- Manish On Thu, Aug 19, 2010 at 1:52 AM, Paul Sexton wrote: > In org, timestamps can be in the usual angle-bracket format, > eg <2010-08-19 +2w>, or you can use lisp s-expressions. These are in the = same > format as the s-expressions used in the 'diary'/'calendar' emacs packages= . I > only discovered these recently but have been able to use them to schedule= some > complex recurring items. I thought I would share the code here. > > 1. Recurring items with a limited number of occurrences > > For example, say you are taking night classes in Spanish. The class is ev= ery > Wednesday evening at 7pm, starting on 18 August, and runs for 8 weeks. AF= AIK > Org's timestamps do not support limited occurrences of recurrent items --= you > have to schedule the item with infinite recurrences, then delete it when = it > finishes. > > To schedule the Spanish classes, put the following in your .emacs: > > (defun diary-limited-cyclic (recurrences interval m d y) > =A0"For use in emacs diary. Cyclic item with limited number of recurrence= s. > Occurs every INTERVAL days, starting on YYYY-MM-DD, for a total of > RECURRENCES occasions." > =A0(let ((startdate (calendar-absolute-from-gregorian (list m d y))) > =A0 =A0 =A0 =A0(today (calendar-absolute-from-gregorian date))) > =A0 =A0(and (not (minusp (- today startdate))) > =A0 =A0 =A0 =A0 (zerop (% (- today startdate) interval)) > =A0 =A0 =A0 =A0 (< (floor (- today startdate) interval) recurrences)))) > > The item in the org file looks like this: > > > ** 19:00-21:00 Spanish lessons > <%%(diary-limited-cyclic 8 7 8 18 2010)> > > > 2. Public holiday that is "the nearest Monday to DATE" > > In New Zealand each regional capital has an "Anniversary Day". The date o= f > Auckland's anniversary day is "the nearest Monday to 29 January". > > Put this in your .emacs: > > (defun calendar-nearest-to (target-dayname target-day target-month) > =A0"Recurring event that occurs in the nearest TARGET-DAYNAME to > the date TARGET-DAY, TARGET-MONTH each year." > =A0(interactive) > =A0(let* ((dayname (calendar-day-of-week date)) > =A0 =A0 =A0 =A0 (target-date (list target-month target-day (calendar-extr= act-year date))) > =A0 =A0 =A0 =A0 (days-diff (abs (- (calendar-day-number date) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(calendar-day-numb= er target-date))))) > =A0 =A0(and (=3D dayname target-dayname) > =A0 =A0 =A0 =A0 (< days-diff 4)))) > > Now we can schedule Auckland Anniversary Day. The first argument, 1, mean= s > Monday (days of the week are numbered starting with Sunday=3D0). > > > *** Auckland Anniversary Day > <%%(calendar-nearest-to 1 29 1)> > > > 3. Public holiday on "the 4th Monday in October". > > This does not require any additions to .emacs: > > > *** Labour Day (NZ) > <%%(diary-float 10 1 4)> > > > 4. Easter > > Easter's date moves around from year to year according to a complicated s= et of > criteria which I do not claim to understand. However the following code w= ill > allow you to schedule recurring events relative to Easter sunday. > > Note: the function da-easter is from: > http://github.com/soren/elisp/blob/master/da-kalender.el > > Put the following in your .emacs: > > (defun da-easter (year) > =A0"Calculate the date for Easter Sunday in YEAR. Returns the date in the > Gregorian calendar, ie (MM DD YY) format." > =A0(let* ((century (1+ (/ year 100))) > =A0 =A0 =A0 =A0 (shifted-epact (% (+ 14 (* 11 (% year 19)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(- (/ (* 3 cen= tury) 4)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(/ (+ 5 (* 8 c= entury)) 25) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(* 30 century)= ) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 30)) > =A0 =A0 =A0 =A0 (adjusted-epact (if (or (=3D shifted-epact 0) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (and (=3D= shifted-epact 1) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0(< 10 (% year 19)))) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (1+ shifted-epact= ) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 shifted-epact)) > =A0 =A0 =A0 =A0 (paschal-moon (- (calendar-absolute-from-gregorian > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (list 4 19 year)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0adjusted-epact))) > =A0 =A0(calendar-dayname-on-or-before 0 (+ paschal-moon 7)))) > > > (defun da-easter-gregorian (year) > =A0(calendar-gregorian-from-absolute (da-easter year))) > > (defun calendar-days-from-easter () > =A0"When used in a diary sexp, this function will calculate how many days > are between the current date (DATE) and Easter Sunday." > =A0(- (calendar-absolute-from-gregorian date) > =A0 =A0 (da-easter (calendar-extract-year date)))) > > Now we can schedule the public holidays associated with Easter as > recurring events. Good Friday is 2 days before "Easter", Easter Monday is= one > day after. > > > *** Good Friday > <%%(=3D -2 (calendar-days-from-easter))> > > *** Easter Sunday > <%%(=3D 0 (calendar-days-from-easter))> > > *** Easter Monday > <%%(=3D 1 (calendar-days-from-easter))> > > > Paul > > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode >