From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id Jx7nBPt1Il9VSgAA0tVLHw (envelope-from ) for ; Thu, 30 Jul 2020 07:25:47 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 6IsTAPt1Il+qOgAAbx9fmQ (envelope-from ) for ; Thu, 30 Jul 2020 07:25:47 +0000 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 DFE3C9403E7 for ; Thu, 30 Jul 2020 07:25:45 +0000 (UTC) Received: from localhost ([::1]:39128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k12wi-0004wn-3c for larch@yhetil.org; Thu, 30 Jul 2020 03:25:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k12wI-0004wS-NG for emacs-orgmode@gnu.org; Thu, 30 Jul 2020 03:25:18 -0400 Received: from www.selma.hfmdk-frankfurt.de ([46.4.92.145]:51928 helo=mail.selma.hfmdk-frankfurt.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k12wF-0005x2-9b for emacs-orgmode@gnu.org; Thu, 30 Jul 2020 03:25:17 -0400 Received: by mail.selma.hfmdk-frankfurt.de (Postfix, from userid 113) id 085B2F60B25; Thu, 30 Jul 2020 09:25:11 +0200 (CEST) Received: from t460s-orm.selma.hfmdk-frankfurt.de (ip-95-223-157-3.hsi16.unitymediagroup.de [95.223.157.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by mail.selma.hfmdk-frankfurt.de (Postfix) with ESMTPSA id E35AAF606FF for ; Thu, 30 Jul 2020 09:25:09 +0200 (CEST) Received: by t460s-orm.selma.hfmdk-frankfurt.de (Postfix, from userid 1000) id 4E0037340218; Thu, 30 Jul 2020 07:25:09 +0000 (UTC) Date: Thu, 30 Jul 2020 09:25:09 +0200 From: Orm Finnendahl To: emacs-orgmode@gnu.org Subject: Re: custom time format extension Message-ID: <20200730072509.GA818435@t480s-orm.localdomain> Mail-Followup-To: emacs-orgmode@gnu.org References: <20200729201634.GA813784@t480s-orm.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200729201634.GA813784@t480s-orm.localdomain> X-Disclaimer: Why are you listening to me? X-Operating-System: GNU/Linux Organization: Hochschule =?utf-8?B?ZsO8?= =?utf-8?Q?r?= Musik und Darstellende Kunst Frankfurt, Frankfurt, Germany Received-SPF: pass client-ip=46.4.92.145; envelope-from=orm.finnendahl@selma.hfmdk-frankfurt.de; helo=mail.selma.hfmdk-frankfurt.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 03:25:12 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 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" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=hfmdk-frankfurt.de (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -0.91 X-TUID: QmnsVV43oMj4 Hi, for the record, here's the code if anyone ever comes across this: (defun same-day-p (timestamp) "check if start and end of timestamp are on the same day." (equal (mapcar (lambda (prop) (or (org-element-property prop timestamp) 0)) '(:day-start :month-start :year-start)) (mapcar (lambda (prop) (or (org-element-property prop timestamp) 0)) '(:day-end :month-end :year-end)))) (defun org-timestamp-translate (timestamp &optional boundary) "Translate TIMESTAMP object to custom format. Format string is defined in `org-time-stamp-custom-formats', which see. When optional argument BOUNDARY is non-nil, it is either the symbol `start' or `end'. In this case, only translate the starting or ending part of TIMESTAMP if it is a date or time range. Otherwise, translate both parts. Return timestamp as-is if `org-display-custom-times' is nil or if it has a `diary' type." (let ((type (org-element-property :type timestamp))) (if (or (not org-display-custom-times) (eq type 'diary)) (org-element-interpret-data timestamp) (let ((same-day (same-day-p timestamp)) (fmt (funcall (if (org-timestamp-has-time-p timestamp) #'cdr #'car) org-time-stamp-custom-formats))) (if (and (not boundary) (memq type '(active-range inactive-range))) (concat (org-timestamp-format timestamp (if (consp fmt) (if same-day (cadr fmt) (car fmt)) fmt)) "--" (org-timestamp-format timestamp (if (consp fmt) (if same-day (caddr fmt) (car fmt)) fmt) t)) (org-timestamp-format timestamp fmt (eq boundary 'end))))))) As mentioned before it should be fully backwards compatible. -- Orm Am Mittwoch, den 29. Juli 2020 um 22:16:34 Uhr (+0200) schrieb Orm Finnendahl: > Hi, > > when exporting timestamps it always bothered me that timestamps with > start and end time on the same day got exported with a full date for > the start and end times separated by a dash. > > After thinking about this for some time I implemented a method today, > which combines the advantage of being utmost flexible while > maintaining full backwards compatibility. > > This is how it works: The cdr of org-time-stamp-custom-formats > normally contains a format string for formatting timestamps with > start/end time. When supplying a list of three strings instead of the > single format string to the cdr of org-time-stamp-custom-formats, the > first, second and third elements of that list are interpreted as > follows: > > The first element is the full format in case start and end of the > timestamp are not on the same day. The second element of the list is > the format string for the start time of the timestamp. The third > element of the list is a format string for the end time of the > timestamp. (BTW: Supplying a list as second element of a dotted list > is equivalent to supplying a list with four strings to > org-time-stamp-custom-formats) > > Below the mail is a short example for german date strings. > > In case somebody is interested, I can provide the code off list. If > any of the maintainers is reading on this list and thinks it should > get revised and maybe adopted for orgmode, please let me know how to > issue pull requests for the code. I tried to be minimally invasive ;-) > > -- > Orm > > ----------- > Example: > > (org-time-stamp-custom-formats '("%a %d.%m.%Y" . ("%a %d.%m.%Y %H:%M Uhr" > "%a %d.%m.%Y %H:%M" > "%H:%M Uhr"))) > > Formatting > > <2020-11-21 Sa> -> Sa 21.11.2020 > > <2020-11-21 Sa 10:00-18:00> -> Sa 21.11.2020 10:00--18:00 Uhr > > > <2020-11-21 Sa 10:00>--<2020-11-22 So 18:00> -> Sa 21.11.2020 10:00 Uhr--So 22.11.2020 18:00 Uhr >