From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id kJAdNWh3emKUOQEAbAwnHQ (envelope-from ) for ; Tue, 10 May 2022 16:32:08 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id GCP0NGh3emLeSgAA9RJhRA (envelope-from ) for ; Tue, 10 May 2022 16:32:08 +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 59BFE5AE3 for ; Tue, 10 May 2022 16:32:08 +0200 (CEST) Received: from localhost ([::1]:59286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1noQuF-000051-Eg for larch@yhetil.org; Tue, 10 May 2022 10:32:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1noQtj-0008VE-Tn for emacs-orgmode@gnu.org; Tue, 10 May 2022 10:31:35 -0400 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]:47095) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1noQtd-0002Rn-DZ for emacs-orgmode@gnu.org; Tue, 10 May 2022 10:31:35 -0400 Received: by mail-lf1-x12f.google.com with SMTP id i10so29642239lfg.13 for ; Tue, 10 May 2022 07:31:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:message-id:date:mime-version:user-agent:subject :content-language:from:to:cc:references:in-reply-to :content-transfer-encoding; bh=QoNDd/2eDWXiVvu6QJqOLxoyG+GFV/CIuyqALhE5IQI=; b=EO6U3CVSw2tQzd1jSHYaH994X3q6hMf7ndo+CZrlmKMk/jIwt000v40at2fKIA8KMg GLIspjQuIG77+cmzzGJgh3M2cEnx2MV3uKAsUFkdBGoY0KBPy6WCZrr6ZFQG06KdAGpF 7ibrW2vkxOk6M3Uf8VkeXT6LWbji9oSwFHgS75gCPCBxs6Cz/zILd/EyK63Q0n6/POkO Tm3jW7s8cLDBIxGrUjBj/0WHwRbPvTfAj4zJKsEP3qKnqno8gSzZBOvBmPXJGnAwEWbP mKnMl3FkVsBONGeA9A2KOyo0Hsu73Uh1Ws61oDGprHgz0EcYac9WupQtKmyHQMWJsrXN XYYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:message-id:date:mime-version:user-agent :subject:content-language:from:to:cc:references:in-reply-to :content-transfer-encoding; bh=QoNDd/2eDWXiVvu6QJqOLxoyG+GFV/CIuyqALhE5IQI=; b=uEj3uiuURoeXIapPCUxvO4WuSmRFHDpmoPjOFf2QTAkXZJpBJyLOe6pHcmLsANqMsi 2eig5qmasOPZrOxwEMyGmn1LNV+AqyXQ4Hx3uoF+lUWChPaZa5O46wtdmg1Etu9nGpHt 2F8dNBrffm7e+CjU0tfz+Gga4qfxFNCzbyRAD31IMNMGSBxSYvAUhcsslWs535I/HDKn z7ojywl/Uyzf0gRgSZk4RtpxkW8ZSTKvlBx5vJEbdved8fBrjLdBmUtJ0gZ3GXLuxiSz Jf5Rac3xPsCJZnCOYhakcLbDEYo+RTuRETLP4txx87SzGhHAhmJA+zKFyG2PxB9KVM57 QCUA== X-Gm-Message-State: AOAM5321am8EQtbFSRXIih9fzPQn+2izWRHsktr8TYTl8h70s6U4K2zS mVcSWtf+ureqZRTErIslLjI= X-Google-Smtp-Source: ABdhPJznUT1Y+LThhzT0OC0U5W11oOrPUsLaq+5Bn+jR43AhrzL+jlkdX4jbm8l5nHzVqUMQT8533g== X-Received: by 2002:a05:6512:3405:b0:473:a5e5:1659 with SMTP id i5-20020a056512340500b00473a5e51659mr16219622lfr.379.1652193087355; Tue, 10 May 2022 07:31:27 -0700 (PDT) Received: from [192.168.0.101] (nat-0-0.nsk.sibset.net. [5.44.169.188]) by smtp.googlemail.com with ESMTPSA id z4-20020a2e3504000000b0024f3d1dae93sm2164686ljz.27.2022.05.10.07.31.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 May 2022 07:31:26 -0700 (PDT) Message-ID: Date: Tue, 10 May 2022 21:31:25 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH v4] org-encode-time compatibility and convenience helper Content-Language: en-US From: Max Nikulin To: Ihor Radchenko Cc: emacs-orgmode@gnu.org, Paul Eggert References: <7f4ea652-7d22-fb61-f873-5e92f078c9e6@gmail.com> <87mtgcmckj.fsf@localhost> <875ymwus9p.fsf@localhost> <8735hpk4ef.fsf@localhost> <2661a0c6-a6a3-6934-16fe-7c987a6a1684@gmail.com> In-Reply-To: <2661a0c6-a6a3-6934-16fe-7c987a6a1684@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2a00:1450:4864:20::12f; envelope-from=manikulin@gmail.com; helo=mail-lf1-x12f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1652193128; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=QoNDd/2eDWXiVvu6QJqOLxoyG+GFV/CIuyqALhE5IQI=; b=FhL9H/U43ZCSd0tto/FN2tZR3XjLNzWEJRr8RzmNyRJ/6zh+0mtS3vAU38kJeqQESC5C5v vuLtHprDXhZepzucH2pBLYCjxRv0beshiHc5160yuyBXNUfYnACfXfZNKQDwTJcRlfX2a7 UirTbNk9Vy2ccJRbIGzv8KV6bpTtXdztO55YJf7Qr42UaWY8l9hW28ogAlDNK8mAXV6BsI rcMnPB3FRSvBxZj9HxPuBWz5FV6ZMpj1tkxx4Chn1nI9acutW4QTmGw2WG/ubR2QCLXVDO mxjJi//OBavHKpvLBd14iDvtonyUylFLYvtZH9zexVJ4/l3A6VymmQM5O7REig== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1652193128; a=rsa-sha256; cv=none; b=eVhT9jyMyNZXNbQOj6XBaKAOrEqTTnemChus41jv8HUCg61aPAmv8fpVeNDl9kgAuIfui/ x3n6mMUu0QyxXWUUxUvFrNj6czh/+rO1gZC+sXiFTqjQNp3SdhH4jRONTsGoxrxD1jiouQ agSNeepWJfLs5Txx99T5z2RYoAV8ULjsz2/axRhWJBhghGqQ6q+PSjlajWD1mzWMhJklVC 1shIosg451IyJP3XNCkK6DnDcAhDjVVyMDMQiF31r/JC2lrJJkLrcdRL3qAf+ZLLQfU/Ga 9HoZqkl/2JE0qwU66h8Yc+9J1aJ6WgFnmSB1SiKhZLlG2YA8hm5t6itmdyK1qw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=EO6U3CVS; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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" X-Migadu-Spam-Score: 9.50 X-Spam: Yes Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=EO6U3CVS; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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" X-Migadu-Queue-Id: 59BFE5AE3 X-Spam-Score: 9.50 X-Migadu-Spam: Yes X-Migadu-Scanner: scn1.migadu.com X-TUID: QbtUvGL9O6o0 On 05/05/2022 22:22, Max Nikulin wrote: > On 04/05/2022 16:56, Ihor Radchenko wrote: >> Max Nikulin writes: >> > Resetting timezone to UTC should be fixed in timestamps generated by a > testing helper function. I was disappointed that `mapcar' can not be > used with multiple lists, but I have found an old function created > namely for zeroing nils in timestamps. Most of the changes are rather trivial. Some code I do not like though or unsure that I chose a proper approach. > + (defmacro org-encode-time (&rest time) > + (pcase (length time) ; Emacs-29 since d75e2c12eb > + (1 `(encode-time ,@time)) > + ((or 6 9) `(encode-time (list ,@time))) > + (_ (error "`org-encode-time' may be called with 1, 6, or 9 arguments but %d given" > + (length time))))) Should it be something like the following? (signal 'wrong-type-argument (list '(1 6 9) (length time))) or even (signal 'wrong-type-argument (list '(lambda (n-args) (memq n-args) '(1 6 9)) (length time))) Usually "wrong type argument" errors give no clue even related to called function til enabling enter debugger on error and realizing how to reproduce the problem. > diff --git a/lisp/org-clock.el b/lisp/org-clock.el > index 9f80dea04..da5c310b7 100644 > --- a/lisp/org-clock.el > +++ b/lisp/org-clock.el > @@ -2866,20 +2866,21 @@ a number of clock tables." > ;; Compute NEXT, which is the end of the current clock table, > ;; according to step. > (let* ((next > - (apply #'encode-time > - (pcase-let > - ((`(,_ ,_ ,_ ,d ,m ,y ,dow . ,_) (decode-time start))) > - (pcase step > - (`day (list 0 0 org-extend-today-until (1+ d) m y)) > - (`week > - (let ((offset (if (= dow week-start) 7 > - (mod (- week-start dow) 7)))) > - (list 0 0 org-extend-today-until (+ d offset) m y))) > - (`semimonth (list 0 0 0 > - (if (< d 16) 16 1) > - (if (< d 16) m (1+ m)) y)) > - (`month (list 0 0 0 month-start (1+ m) y)) > - (`year (list 0 0 org-extend-today-until 1 1 (1+ y))))))) > + ;; In Emacs-27 and Emacs-28 `encode-time' does not support 6 elements > + ;; list argument so `org-encode-time' can not be outside of `pcase'. > + (pcase-let > + ((`(,_ ,_ ,_ ,d ,m ,y ,dow . ,_) (decode-time start))) > + (pcase step > + (`day (org-encode-time 0 0 org-extend-today-until (1+ d) m y)) > + (`week > + (let ((offset (if (= dow week-start) 7 > + (mod (- week-start dow) 7)))) > + (org-encode-time 0 0 org-extend-today-until (+ d offset) m y))) > + (`semimonth (org-encode-time 0 0 0 > + (if (< d 16) 16 1) > + (if (< d 16) m (1+ m)) y)) > + (`month (org-encode-time 0 0 0 month-start (1+ m) y)) > + (`year (org-encode-time 0 0 org-extend-today-until 1 1 (1+ y)))))) > (table-begin (line-beginning-position 0)) > (step-time > ;; Write clock table between START and NEXT. I do not like repeating of `org-encode-time' but do not see another way till Emacs-29 will become the lowest supported version. > diff --git a/lisp/org.el b/lisp/org.el > index 165c83609..3288bb7b8 100644 > --- a/lisp/org.el > +++ b/lisp/org.el > @@ -14472,14 +14474,15 @@ When SUPPRESS-TMP-DELAY is non-nil, suppress delays like > (setcar (cdr time0) (+ (nth 1 time0) > (if (> n 0) (- rem) (- dm rem)))))) > (setq time > - (apply #'encode-time > - (or (car time0) 0) > - (+ (if (eq timestamp? 'minute) n 0) (nth 1 time0)) > - (+ (if (eq timestamp? 'hour) n 0) (nth 2 time0)) > - (+ (if (eq timestamp? 'day) n 0) (nth 3 time0)) > - (+ (if (eq timestamp? 'month) n 0) (nth 4 time0)) > - (+ (if (eq timestamp? 'year) n 0) (nth 5 time0)) > - (nthcdr 6 time0))) > + (org-encode-time > + (apply #'list > + (or (car time0) 0) > + (+ (if (eq timestamp? 'minute) n 0) (nth 1 time0)) > + (+ (if (eq timestamp? 'hour) n 0) (nth 2 time0)) > + (+ (if (eq timestamp? 'day) n 0) (nth 3 time0)) > + (+ (if (eq timestamp? 'month) n 0) (nth 4 time0)) > + (+ (if (eq timestamp? 'year) n 0) (nth 5 time0)) > + (nthcdr 6 time0)))) > (when (and (memq timestamp? '(hour minute)) > extra > (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra)) I am tempting to write something like (let* ((ts (copy-sequence time0)) (ord (memq timestamp? '(year month day hour minute))) (field (and ord (nthcdr (length ord) ts)))) (when field (setcar field (+ (car field) n))) (org-encode-time ts)) but I am afraid it will make the code rather obscure. > @@ -19276,12 +19279,14 @@ return an active timestamp." > "Convert TIMESTAMP object into an Emacs internal time value. > Use end of date range or time range when END is non-nil. > Otherwise, use its start." > - (apply #'encode-time 0 > - (mapcar > - (lambda (prop) (or (org-element-property prop timestamp) 0)) > - (if end '(:minute-end :hour-end :day-end :month-end :year-end) > - '(:minute-start :hour-start :day-start :month-start > - :year-start))))) > + (org-encode-time > + (append '(0) > + (mapcar > + (lambda (prop) (or (org-element-property prop timestamp) 0)) > + (if end '(:minute-end :hour-end :day-end :month-end :year-end) > + '(:minute-start :hour-start :day-start :month-start > + :year-start))) > + '(nil -1 nil)))) > > (defun org-timestamp-has-time-p (timestamp) > "Non-nil when TIMESTAMP has a time specified." Hardly may be considered as an example of elegant code.