From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id ONVJKxIbrWTJ4wAASxT56A (envelope-from ) for ; Tue, 11 Jul 2023 11:04:18 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id kDoaKhIbrWTb2gAAG6o9tA (envelope-from ) for ; Tue, 11 Jul 2023 11:04:18 +0200 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 6C9E73AEEC for ; Tue, 11 Jul 2023 11:04:17 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=eNlvsp1+; dmarc=pass (policy=none) header.from=posteo.net; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1689066258; 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=V0m3+AuBgM3TiKmzmfUfFsvlwDatqHwdvMUOeXS4Oqg=; b=VkJGu8QBIteKjXbihMimREBGPCGXAMREURYObEWGQYMNN4djOKfVG5d4ovWZwF9pZZe0J4 k1ehMm2KlYoM/+p3eFW/uL+qdwAH6flap1fwV4S45bJeSZs/57ZgRfA8P+NIJnj6MhVShM HMS8NF5KNVuzi3EHvJc3ZW6/Wuam5lJKa96mhPHyBWA0ukabB5Aoz8oEi8RQW/FNHRUoW6 VRR+iuO51G4wcxSkgknRzpb+xaJgBOqKDpsZuMRIYJiQfeTD01gBEZv5da8SVooM2f6Ov/ GkVNEaJBNr3Eh2BlwCDvT0MAhJk3cmAxyIVk3M/mEydqE+ebzKM1raZX/Ilq6w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=eNlvsp1+; dmarc=pass (policy=none) header.from=posteo.net; 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" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1689066258; a=rsa-sha256; cv=none; b=HjfKjWaAsYFjEe2SqUVyz0uRISddoI4smxazNxYWB7PKkirTxeg/ahhpjN4NwEVY5JujWl dD2rFMXzrJ7JHe3uh3/Vi2yzlYZUYbdXF1ay3y6B+kaI3SWvjHqBB01ZcgC21sG+l0ug2C vqFfUJKyy8mO1d+77rGYSpzc+RqybO4Jho6xqx9SeXTlGZ1OZVJbAg58wdY4AhQDSZFeSt TpZTmAe7ZfHnCzj+xhSshqJBc4MzqwmAK0rJJjcxghftgOSiCAroxjV9MQJDIxpx3YNGyp sWnjC0eMlV+OQ/Y+HATeAjN1btL+UAeXlgnWjpsHl/8r5k8qXfrMTqiDzTeKyw== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJ9Gv-0005TR-HV; Tue, 11 Jul 2023 05:03:01 -0400 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 1qJ9Gp-0005T4-IU for emacs-orgmode@gnu.org; Tue, 11 Jul 2023 05:02:55 -0400 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJ9Gf-0001FQ-Vs for emacs-orgmode@gnu.org; Tue, 11 Jul 2023 05:02:48 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 855E6240028 for ; Tue, 11 Jul 2023 11:02:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1689066162; bh=ff7neTrvrxO0yEFd+qF7IjKi0Uy+ptAI300fPEFX+gk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=eNlvsp1+7MbNb/tYRtBD0Pljp9Y+eUxQlWgIhxOJ9jr59xxKAv2IIarY2JiB71wIp tdS4+fJutnnW9V3asFB0WUhL+gwhbmggLNP0QWVqdV4fmqDDvC3iHvZqxf8TbFa+AZ cWseeSc5licgC4ONYbHlEcg5kLI+yi/SEXI9SmrrXNyj582vBHduBjrXJqrtFTQbrP B5Sy1u01vstZX/8FgbQGuHIpFItmFLgJYg/JeldHV+8yqCon6Z18AZS/yfUw+7Dj1k Mwnz1c+EI7a5XA0nLZlgEgF/5RLTOHvY2isGJYdlNQBxHHdV8DyGfea/2XvBN2eLBd qTjxOZdrNHjeA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4R0ZdY4Szwz9rxW; Tue, 11 Jul 2023 11:02:41 +0200 (CEST) From: Ihor Radchenko To: Ilya Chernyshov Cc: emacs-orgmode Subject: Re: [PATCH] org-element-timestamp-interpreter: Return daterange anyway, if DATERANGE is non-nil In-Reply-To: <87edlfljcx.fsf@gmail.com> References: <87y1ot6dqz.fsf@gmail.com> <87wn4cegt4.fsf@localhost> <9E22693E-7D20-470A-B57B-EA17BBE9160F@gmail.com> <87a616c5do.fsf@localhost> <87wmzi4s6n.fsf@localhost> <87edlkyyit.fsf@gmail.com> <87ttueajih.fsf@localhost> <87edlfljcx.fsf@gmail.com> Date: Tue, 11 Jul 2023 09:02:45 +0000 Message-ID: <87o7kiom6i.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -9.27 X-Spam-Score: -9.27 X-Migadu-Queue-Id: 6C9E73AEEC X-Migadu-Scanner: mx1.migadu.com X-TUID: 4kSxTebQ5Mqz --=-=-= Content-Type: text/plain Ilya Chernyshov writes: > Preserved old behavior for `org-element-timestamp-interpreter' > function for :range-type set to `nil'. The new function > > The new function takes into account :range-type value when interpreting > ranges and throws error when :range-type set for `active'/`inactive' > types. Thanks! The patch looks good in general, but there is at least one test failing when I run make test. May you please check? Also, see the attached diff where I suggest some comments to explain the code logic. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=extra-comments.diff diff --git a/lisp/org-element.el b/lisp/org-element.el index 203f45a33..baa605548 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -4152,6 +4152,8 @@ (defun org-element-timestamp-interpreter (timestamp _) (let ((day-start (org-element-property :day-start timestamp)) (month-start (org-element-property :month-start timestamp)) (year-start (org-element-property :year-start timestamp))) + ;; Return nil when start date is not available. Could also + ;; throw an error, but the current behavior is historical. (when (and day-start month-start year-start) (let* ((repeat-string (concat @@ -4184,39 +4186,82 @@ (defun org-element-timestamp-interpreter (timestamp _) (and (org-string-nw-p warning-string) (concat " " warning-string)) (cdr brackets)))) (concat + ;; Opening backet: [ or < (car brackets) + ;; Starting date/time: YYYY-MM-DD DAY[ HH:MM] (format-time-string - (org-time-stamp-format (when (and minute-start hour-start) t) 'no-brackets) + ;; `org-time-stamp-formats'. + (org-time-stamp-format + ;; Ignore time unless both HH:MM are available. + ;; Ignore means (car org-timestamp-formats). + (and minute-start hour-start) + 'no-brackets) (org-encode-time 0 (or minute-start 0) (or hour-start 0) day-start month-start year-start)) - (let((hour-end (org-element-property :hour-end timestamp)) - (minute-end (org-element-property :minute-end timestamp))) + ;; Range: -HH:MM or TIMESTAMP-END--[YYYY-MM-DD DAY HH:MM] + (let ((hour-end (org-element-property :hour-end timestamp)) + (minute-end (org-element-property :minute-end timestamp))) (pcase type ((or `active `inactive) + ;; `org-element-timestamp-parser' use this type + ;; when no time/date range is provided. So, + ;; should normally return nil in this clause. (pcase range-type (`nil + ;; `org-element-timestamp-parser' will never assign end times here. + ;; End time will always imply `active-range' or `inactive-range' TYPE. + ;; But manually built timestamps may contain + ;; anything, so check for end times anyway. (when (and hour-start hour-end minute-start minute-end (or (/= hour-start hour-end) (/= minute-start minute-end))) + ;; Could also throw an error. Return range + ;; timestamp nevertheless to preserve + ;; historical behavior. (format "-%02d:%02d" hour-end minute-end))) ((or `timerange `daterange) (error "`:range-type' must be `nil' for `active'/`inactive' type")))) + ;; Range must be present. ((or `active-range `inactive-range) (pcase range-type + ;; End time: -HH:MM. + ;; Fall back to start time if end time is not defined (arbitrary historical choice). + ;; Error will be thrown if both end and begin time is not defined. (`timerange (format "-%02d:%02d" (or hour-end hour-start) (or minute-end minute-start))) - ((or `nil `daterange) + ;; End date: TIMESTAMP-END--[YYYY-MM-DD DAY HH:MM + ((or `daterange + ;; Should never happen in the output of `org-element-timestamp-parser'. + ;; Treat as an equivalent of `daterange' arbitrarily. + `nil) (concat + ;; repeater + warning + closing > or ] + ;; This info is duplicated in date ranges. timestamp-end "--" (car brackets) (format-time-string - (org-time-stamp-format (when (and minute-end hour-end) t) 'no-brackets) + ;; `org-time-stamp-formats'. + (org-time-stamp-format + ;; Ignore time unless both HH:MM are available. + ;; Ignore means (car org-timestamp-formats). + (and minute-end hour-end) + 'no-brackets) (org-encode-time + ;; Closing HH:MM missing is a valid scenario. 0 (or minute-end 0) (or hour-end 0) + ;; YEAR/MONTH/DAY-END will always be present + ;; for `daterange' range-type, as parsed by + ;; `org-element-timestamp-parser'. + ;; For manually constructed timestamp + ;; object, arbitrarily fall back to starting + ;; date. (or (org-element-property :day-end timestamp) day-start) (or (org-element-property :month-end timestamp) month-start) (or (org-element-property :year-end timestamp) year-start))))))))) + ;; repeater + warning + closing > or ] + ;; This info is duplicated in date ranges. timestamp-end)))) + ;; diary type. (org-element-property :raw-value timestamp)))) ;;;; Underline --=-=-= Content-Type: text/plain And please provide an additional patch for WORG: https://orgmode.org/worg/dev/org-element-api.html#org6ae377e -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--