From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:700:3204::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id 0DqJBy9zoWUYAAAAkFu2QA (envelope-from ) for ; Fri, 12 Jan 2024 18:13:19 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id oKn+Ai9zoWXhIAEAe85BDQ (envelope-from ) for ; Fri, 12 Jan 2024 18:13:19 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mNGrTjAk; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1705079599; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=izrXnwYUHY4gixSKY7ZMyU1DNLv8WRWNUyoWq0yOxik=; b=J5v4b6X7Xo/M3Q/2ulC01XwHLNfs8wlfU0VSckPUiEKCx7lmRAbcGkG1y1nxdWA4/ouWvL VsEdNsdKwtFiEb/Ro5XWvQg7X+yPW0wAoTcsBWDr+EIqd3Mwc7AwciOlPRCL9o8jLy8wmf g/syj5Lps3mT1fkYu1eKTEofKpZtRAF75LG8oZi/3nOvPA7doKBWt3RDF0/0vrB063WC7+ LATmWc6ftHtKDUyjRmxHst/K6AZ25Q5JfwMgFKE8zY4zsxJrWusI9s3UhaljaiNn8UyXuN ffd0VlrtztOCFaLZ9UPUyymgFB8SUQ8/S6vuev0/Bc5zPlAS0WCZsoP9wRfVhA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mNGrTjAk; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1705079599; a=rsa-sha256; cv=none; b=mmO7uzxDX+d8B0g11WUtaZFhkpUSX0JoTiEV/hQ9sfzCQbkoaL7rxXP4YFPoQpzWFOA9Qi 5erIEA2FcJwiS/pHN9tVUOQdoMmGDVLolMqQF6WwjKKlinY6R/v+oz2f3i3F19l4j8oDGS kx++ilT3RUIrm5OFVBChVJku6taiT1VVcjzEUSP4poINni5K145kXzcMmxhpNqcGj9ZglA Mnbb33Z0bnpczJoOkib/5BCw/ajtBFRZ+fpU+i7GS3WrOi14BorhbzJ7rc27SeEm4hwn3Y L8UIBC+4/p958hmY59aLYbtqwHWOmcXXyafpmHGHxEFAbxzlXIYakq5+LSRALQ== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D8BED39881 for ; Fri, 12 Jan 2024 18:13:18 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rOL4t-0001d5-QS; Fri, 12 Jan 2024 12:12:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rOL4l-0001cl-HG for emacs-orgmode@gnu.org; Fri, 12 Jan 2024 12:12:11 -0500 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rOL4j-0008Tv-Pq for emacs-orgmode@gnu.org; Fri, 12 Jan 2024 12:12:11 -0500 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-28c0d8dd88bso4744530a91.2 for ; Fri, 12 Jan 2024 09:12:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705079527; x=1705684327; darn=gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=izrXnwYUHY4gixSKY7ZMyU1DNLv8WRWNUyoWq0yOxik=; b=mNGrTjAk8rIBn1ci8OpaxF5BNfEIw44HkL1RZBJ5NKNyxZWokLwU9lh5mM5zLe36Hx hQKug9ILBtR6291FLUCZs0k1TBfwTWWs+K/tbtMAaZ94DLP/2Ql2JH7nc8CJAId3A8Re jUdsy+wxxOWcL0oNhFqd+kIQIihSAdHZfJ1LoL735flYzJi2pPipPa5ICpkqTJEe9zZS byokBR37Nf8kzyuF/l8F7eqnUw9pqGz3PrExMb4975+8QaMS2J0fB/jhpy7eZc50PmPv uSmc+/YdK4LS815X8kOFgXivqFinnhTVSgew2aP2zVlDj3hDCeVV25YSifJBwjddGHI0 4mJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705079527; x=1705684327; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=izrXnwYUHY4gixSKY7ZMyU1DNLv8WRWNUyoWq0yOxik=; b=mZTEv+11yB6bZfdPv78rXwi1h1f6pfl8+2Hx4hCSKc9jEzDc3AsajOZ6UvaVtDc9gK eQThuEccBEGJqWGLBJ8AhN2B9ZG94zpmeqi2OgS3B/xGzSKaAzToWp1QtD74Kxdy4VfH 9U7dwYGarUtC9anfc69Q/1kDYD+9GcjJHgoKlwWE4xi2JkI0LKrwRTrJj9241j4vhTU2 w7Xo9bYJwVhC36Blp5Uj6in2Gq/rGcKtI/5BIHNdN1Z5FKhSGFd99iiU7RAIH7RFAdL9 PUvSBdDSNGNurXAHEGFdHwdmXr0HgZqjQcHrjdeXgNnVdWU1D1v7kY8GqBY677alocqA YfsA== X-Gm-Message-State: AOJu0YxjQ3fFIQRm0SL9fRz7WkleHoSAbPjR2E81LEarJG/Xf09qXAID tiybyiSxsWlaxsgWnGGMBdzy8Mka6DlsRDVG X-Google-Smtp-Source: AGHT+IGU1SU2D5D+NaSFSpZGj2cni1zQOq8+FOcfgd1cVULwX81YeVFzhQnhnxhvDJ49KebIF9qDaQ== X-Received: by 2002:a17:90a:68c9:b0:28b:ccc3:d4fa with SMTP id q9-20020a17090a68c900b0028bccc3d4famr1414966pjj.1.1705079526860; Fri, 12 Jan 2024 09:12:06 -0800 (PST) Received: from t480 ([129.222.170.55]) by smtp.gmail.com with ESMTPSA id li4-20020a17090b48c400b0028dfdee16c6sm2837004pjb.24.2024.01.12.09.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 09:12:06 -0800 (PST) References: User-agent: mu4e 1.8.15; emacs 28.1 From: Ken Mankoff To: David Rogers Cc: emacs-orgmode@gnu.org Subject: Re: Diary sexp and comparing dates, agenda In-reply-to: Date: Fri, 12 Jan 2024 10:11:56 -0800 Message-ID: <87bk9ql8ur.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=mankoff@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -3.02 X-Migadu-Queue-Id: D8BED39881 X-Spam-Score: -3.02 X-Migadu-Scanner: mx11.migadu.com X-TUID: C5iCDWyr+Pmf Hi David, I'm not sure if this will help, but I have to file time sheets on the last weekday less than or equal to the 15th and last-day-of-month. I wrote two diary functions to achieve this (I don't handle holiday edge cases). I use these functions with: ** INFO [#A] Time Sheet <%%(kdm/diary-last-weekday-of-month date)> <%%(kdm/diary-last-weekday-15th date)> Functions are: (defun kdm/diary-last-weekday-15th (date) (let* ( (dow (calendar-day-of-week date)) (dom (calendar-extract-day date)) (weekday (and (>= dow 1) (<= dow 5)))) (or (and weekday (= dom 15)) (and (= dow 5) (= dom 14)) (and (= dow 5) (= dom 13))))) (defun kdm/diary-last-weekday-of-month (date) (let* ( (dow (calendar-day-of-week date)) (dom (calendar-extract-day date)) (month (calendar-extract-month date)) (year (calendar-extract-year date)) (ldom-num (calendar-last-day-of-month month year)) (weekday (and (>= dow 1) (<= dow 5)))) (or (and weekday (= dom ldom-num)) (and (= dow 5) (= (+ 1 dom) ldom-num)) (and (= dow 5) (= (+ 2 dom) ldom-num))))) -k. On 2024-01-11 at 21:58 -08, David Rogers wrote... > Hello all > > I'm using the Org agenda to show when certain church occasions will > happen. Mostly I've got them working correctly, after "stealing" the > method used in holidays.el for finding the date of Easter, along with > someone else's function that then uses that to find the difference > between Easter and today. (I'm pretty sure that whole idea was on > emacswiki, and I think Paul Sexton put it together.) > > So now I have a much smaller problem to solve, but I don't understand > how to get it to work; I suspect it has to do with how dates get > formatted within different functions. Using what I already have, I can > do this: > > * Example 1 <%%(= 245 (mf-days-from-easter))> > > because "mf-days-from-easter" is defined in my init file, along with > the definition of Easter itself. This does what it looks like it > should do; this year, Example 1 is shown on December 1. > > And I can do > > * Example 2 <%%(and (diary-float 1 0 5 7) (<= (mf-days-from-easter) > -56))> > > to say "five Sundays after January 6th, but only if Easter is still 8 > weeks away or more". > > But Example 1 isn't quite finished, because that date is too close to > Christmas. I can easily show a diary sexp defining when "too close to > Christmas" is: > > <%%(diary-float 12 0 -4 24)> > > So I want to combine these ideas, to say "Show Example 1 in the agenda > 245 days after Easter each year, but only if it's earlier than the > fourth Sunday before Christmas". > > I could do a long string of (and (not this day, not this day, etc etc > [insert long list of days] . . . , but that seems like a last resort. > > Everything in this question fits into "the current year according to > the agenda view" - there's no need to consider dates that cross a year > boundary. > > So: Is there a fairly simple way to define a (mf-days-from-advent) > that will do a similar job to what (mf-days-from-easter) is already > doing (i.e. it works when used in a diary sexp)? > > > Here are the relevant definitions I've been using: > > > (defun mf-easter (displayed-year) > (let* ((century (1+ (/ displayed-year 100))) > (shifted-epact ; age of moon for April 5... > (% (+ 14 (* 11 (% displayed-year 19)) ; ...by Nicaean > rule > (- ; ...corrected for the Gregorian century rule > (/ (* 3 century) 4)) (/ ; ...corrected for > Metonic cycle inaccuracy > (+ 5 (* 8 century)) 25) (* 30 century)) ; keeps > value positive > 30)) (adjusted-epact ; adjust for 29.5 day month > (if (or (zerop shifted-epact) > (and (= shifted-epact 1) (< 10 (% > displayed-year 19)))) > (1+ shifted-epact) shifted-epact)) > (paschal-moon ; day after the full moon on or after > March 21 > (- (calendar-absolute-from-gregorian (list 4 19 > displayed-year)) > adjusted-epact))) (calendar-dayname-on-or-before 0 > (+ paschal-moon 7)))) > > > > (defun mf-days-from-easter () > "When used in a diary sexp, this function will calculate how many > days are between the current date (DATE) and Easter Sunday." > (- (calendar-absolute-from-gregorian date) > (mf-easter (calendar-extract-year date))))