emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] org-element-timestamp-interpreter: Return daterange anyway,


From: Ihor Radchenko
Subject: Re: [PATCH] org-element-timestamp-interpreter: Return daterange anyway, if DATERANGE is non-nil
Date: Sun, 02 Jul 2023 08:46:08 +0000

Ilya Chernyshov <ichernyshovvv@gmail.com> writes:

> In the new patch I added :range-type timestamp property, adjusted
> interpreter,
> parser functions, added tests for the property.

Thanks!

Some general stylistic comments:

1. You left some whitespace-only blank lines and spaces at the end of
   lines. Please, clean them up.
2. Please, use double space between sentences in the commit message and
   link to this thread. See
   https://orgmode.org/worg/org-contribute.html#commit-messages
3. I noticed some (let((...) forms. Please put spaces between sexps like
   (let ((...)
       ^ space here

> * lisp/org-element (org-element-timestamp-parser): Add :range-type property

Dot is missing at the end of the sentence here.

>  (defun org-element-timestamp-interpreter (timestamp _)
>    "Interpret TIMESTAMP object as Org syntax."
> ...
> +              (concat
> +                  "<" start-date (and start-time (concat " " start-time))
> +                  (if date-range-p
> +                      (concat ">--<" end-date (and end-time (concat " " 
> end-time)))
> +                    (if time-range-p (concat "-" end-time)))
> +                  ">")))

Here, you are manually constructing time part of the timestamp,
bypassing `org-time-stamp-format' and `org-timestamp-formats'. Please,
use `org-time-stamp-format' for times as well.
If necessary, feed free to extend `org-time-stamp-format' and the value
of `org-timestamp-formats' constant.

> +         (dolist (s (list repeat-string warning-string))
> +           (when (org-string-nw-p s)
> +             (setq ts (string-replace ">" (concat " " s ">") ts))))
> +         (pcase (org-element-property :type timestamp)
> +              ((or `active `active-range)
> +               ts)
> +              ((or `inactive `inactive-range)
> +               (string-replace
> +                "<" "["
> +                (string-replace ">" "]" ts)))))))

`string-replace' is fragile here. If we ever need to put "<" or ">"
inside timestamp, random breakages may happen. Please, rewrite.



>    (should
>     (string-match
> -    "\\[2012-03-29 .* 16:40\\]--\\[2012-03-29 .* 16:41\\]"
> +    "\\[2012-03-29 .* 16:40-16:41\\]"
>      (org-element-timestamp-interpreter
>       '(timestamp
>         (:type inactive-range :year-start 2012 :month-start 3 :day-start 29
>             :hour-start 16 :minute-start 40 :year-end 2012 :month-end 3
>             :day-end 29 :hour-end 16 :minute-end 41)) nil)))
> +  
>    ;; Diary.
>    (should (equal (org-test-parse-and-interpret "<%%diary-float t 4 2>")
>                "<%%diary-float t 4 2>\n"))
> -- 
> 2.40.1

> * lisp/org-element (org-element-timestamp-interpreter): For ranges:
> When :range-type is nil or `timerange', return timerange (<YYYY-mm-DD
> HH:MM-HH:MM>) if date-start and date-end are equal; return
> daterange(<...>--<...>) otherwise. When :range-type is `daterange',
> return daterange anyway. Refactor the code.

Interpreting timestamps with :time-range nil and
:day-end/:year-end/:month-end non-nil as timerange is a breaking change.
Let's avoid it.

With the new version of the parser, the test example will never happen,
but the tested AST structure might happen in the wild - we do not want
to break anything when it is not necessary.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]