From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/83894 Path: news.gmane.org!not-for-mail From: Jan Tatarik Newsgroups: gmane.emacs.gnus.general Subject: PATCH: gnus-icalendar: fix org-timestamp for events ending at midgnight Date: Tue, 19 Nov 2013 23:25:54 +0100 Message-ID: <87d2lw111p.fsf@nb-jtatarik2.xing.hh> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1384899994 19286 80.91.229.3 (19 Nov 2013 22:26:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 Nov 2013 22:26:34 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M32150@lists.math.uh.edu Tue Nov 19 23:26:38 2013 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Vitki-0007SF-Em for ding-account@gmane.org; Tue, 19 Nov 2013 23:26:36 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1VitkK-0001bq-Tu; Tue, 19 Nov 2013 16:26:12 -0600 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1VitkI-0001bX-2l for ding@lists.math.uh.edu; Tue, 19 Nov 2013 16:26:10 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) (envelope-from ) id 1VitkG-0002uJ-Jx for ding@lists.math.uh.edu; Tue, 19 Nov 2013 16:26:09 -0600 Original-Received: from mail-bk0-f48.google.com ([209.85.214.48]) by quimby.gnus.org with esmtp (Exim 4.80) (envelope-from ) id 1VitkE-0003H8-TB for ding@gnus.org; Tue, 19 Nov 2013 23:26:06 +0100 Original-Received: by mail-bk0-f48.google.com with SMTP id v10so2664992bkz.7 for ; Tue, 19 Nov 2013 14:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type; bh=Ilr77nX7yLEHiMXrgvYRA39EFgb+sZefGKSQ9MRB/tM=; b=IqbFsHvVzqWIP2TZnHmbJ5lAvm00TgmjLiaP6XOBFrgAX1IkLQ2Jw4EqmFKCsvkB9r Hv2i7he//47vWmDUbKgDssTpyH/mLqeuC2dO/HASRgfNWQet2LYc8PKhuekEyb5O0e8c N41/0f3GAjWh1vnI/+xKs7zGN41MwBiCt7CFiqcIz+DfUJ5vcBkmCrGlDk6SaoLVMc4J AkKQkav8PQM44s+xbtRo1AWmKeW4nl2m0BcKIf9NTVg7mOp2kYunLJRmd93OyZGzbOlo cUyPuh1oJvJzX8rWmERpGk9pDt4nBj8oFNA2UB2tZcEp9fYeq9jE16H8809Wr41HSBYo ucwA== X-Received: by 10.204.247.71 with SMTP id mb7mr18031394bkb.7.1384899961403; Tue, 19 Nov 2013 14:26:01 -0800 (PST) Original-Received: from nb-jtatarik2.xing.hh (f054078216.adsl.alicedsl.de. [78.54.78.216]) by mx.google.com with ESMTPSA id pk7sm22013772bkb.2.2013.11.19.14.25.59 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 19 Nov 2013 14:26:00 -0800 (PST) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Spam-Score: -3.0 (---) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:83894 Archived-At: --=-=-= Content-Type: text/plain Hi, I just discovered that typical all-day event org timestamp <2013-11-19 Tue 00:00>--<2013-11-20 Wed 00:00> will produce two entries in the org agenda - one for the 19th (expected) and another one for the 20th (incorrect). It would be similar for any event ending at midnight. The enclosed patch fixes the org agenda issue by either omitting the start/end times entirely (e.g. for all-day events) <2013-11-19 Tue> or by generating end time of 23:59 on the day before <2013-11-19 Tue 18:00>--<2013-11-19 Tue 23:59> --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=all_day_event_fix.patch diff --git a/lisp/gnus-icalendar.el b/lisp/gnus-icalendar.el index a8277635f3e1571722a01cb4b0fe4452ca7d2434..5fbb6e73b3448e744c0579edfa375ac07d6a31d3 100644 --- a/lisp/gnus-icalendar.el +++ b/lisp/gnus-icalendar.el @@ -387,14 +387,46 @@ Return nil for non-recurring EVENT." (end (gnus-icalendar-event:end-time event)) (start-date (format-time-string "%Y-%m-%d %a" start)) (start-time (format-time-string "%H:%M" start)) + (start-at-midnight (string= start-time "00:00")) (end-date (format-time-string "%Y-%m-%d %a" end)) (end-time (format-time-string "%H:%M" end)) + (end-at-midnight (string= end-time "00:00")) + (start-end-date-diff (/ (float-time (time-subtract + (date-to-time end-date) + (date-to-time start-date))) + 86400)) (org-repeat (gnus-icalendar-event:org-repeat event)) - (repeat (if org-repeat (concat " " org-repeat) ""))) - - (if (equal start-date end-date) - (format "<%s %s-%s%s>" start-date start-time end-time repeat) - (format "<%s %s>--<%s %s>" start-date start-time end-date end-time)))) + (repeat (if org-repeat (concat " " org-repeat) "")) + (time-1-day '(0 86400))) + + ;; NOTE: special care is needed with appointments ending at midnight + ;; (typically all-day events): the end time has to be changed to 23:59 to + ;; prevent org agenda showing the event on one additional day + (cond + ;; start/end midnight + ;; A 0:0 - A+1 0:0 -> A + ;; A 0:0 - A+n 0:0 -> A - A+n-1 + ((and start-at-midnight end-at-midnight) (if (> start-end-date-diff 1) + (let ((end-ts (format-time-string "%Y-%m-%d %a" (time-subtract end time-1-day)))) + (format "<%s>--<%s>" start-date end-ts)) + (format "<%s%s>" start-date repeat))) + ;; end midnight + ;; A .:. - A+1 0:0 -> A .:.-23:59 + ;; A .:. - A+n 0:0 -> A .:. - A_n-1 + (end-at-midnight (if (= start-end-date-diff 1) + (format "<%s %s-23:59%s>" start-date start-time repeat) + (let ((end-ts (format-time-string "%Y-%m-%d %a" (time-subtract end time-1-day)))) + (format "<%s %s>--<%s>" start-date start-time end-ts)))) + ;; start midnight + ;; A 0:0 - A .:. -> A 0:0-.:. (default 1) + ;; A 0:0 - A+n .:. -> A - A+n .:. + ((and start-at-midnight + (plusp start-end-date-diff)) (format "<%s>--<%s %s>" start-date end-date end-time)) + ;; default + ;; A .:. - A .:. -> A .:.-.:. + ;; A .:. - B .:. + ((zerop start-end-date-diff) (format "<%s %s-%s%s>" start-date start-time end-time repeat)) + (t (format "<%s %s>--<%s %s>" start-date start-time end-date end-time))))) (defun gnus-icalendar--format-summary-line (summary &optional location) (if location --=-=-=--