Gnus development mailing list
 help / color / mirror / Atom feed
* PATCH: gnus-icalendar: fix org-timestamp for events ending at midgnight
@ 2013-11-19 22:25 Jan Tatarik
  2013-11-21 22:42 ` Adam Sjøgren
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Tatarik @ 2013-11-19 22:25 UTC (permalink / raw)
  To: ding

[-- Attachment #1: Type: text/plain, Size: 530 bytes --]

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>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: all_day_event_fix.patch --]
[-- Type: text/x-diff, Size: 3061 bytes --]

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PATCH: gnus-icalendar: fix org-timestamp for events ending at midgnight
  2013-11-19 22:25 PATCH: gnus-icalendar: fix org-timestamp for events ending at midgnight Jan Tatarik
@ 2013-11-21 22:42 ` Adam Sjøgren
  0 siblings, 0 replies; 2+ messages in thread
From: Adam Sjøgren @ 2013-11-21 22:42 UTC (permalink / raw)
  To: ding

Jan Tatarik <jan.tatarik@gmail.com> writes:

> The enclosed patch fixes the org agenda issue by either omitting the
> start/end times entirely (e.g. for all-day events)

Thanks; applied.

 * http://git.gnus.org/cgit/gnus.git/commit/?id=8dce88ccd2f52661a97d50c4f62226ded8dfe46f


  Best regards,

    Adam

-- 
 "I don't care about issues! I've got better things to        Adam Sjøgren
  do than argue with every wrong-headed crackpot with    asjo@koldfront.dk
  an ignorant opinion. I'm a busy man!"




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-11-21 22:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-19 22:25 PATCH: gnus-icalendar: fix org-timestamp for events ending at midgnight Jan Tatarik
2013-11-21 22:42 ` Adam Sjøgren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).