From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.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 UJB7IRd2fmLeQwAAbAwnHQ (envelope-from ) for ; Fri, 13 May 2022 17:15:35 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id EO6BIBd2fmJWdwAAG6o9tA (envelope-from ) for ; Fri, 13 May 2022 17:15:35 +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 1509E1531B for ; Fri, 13 May 2022 17:15:35 +0200 (CEST) Received: from localhost ([::1]:34910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npX0v-0002Fw-Qu for larch@yhetil.org; Fri, 13 May 2022 11:15:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npX02-0002Dk-Qi for emacs-orgmode@gnu.org; Fri, 13 May 2022 11:14:39 -0400 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]:41627) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npX00-0003Jr-Us for emacs-orgmode@gnu.org; Fri, 13 May 2022 11:14:38 -0400 Received: by mail-lf1-x132.google.com with SMTP id j4so15059168lfh.8 for ; Fri, 13 May 2022 08:14:36 -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:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=WaLaWmqzSNmNiJqczhgiO4T48KRhGKoouD6uD1vGyCY=; b=jYeMVL0MvVtAzRhs4Ff6axTrsJYumaI5cRlHcj/ehl/Pwcj81sVBv5qE9pwdtHtnDJ dRgREfIMFFG+cXbifrEuLc4jj6HNB4z4hJpu1SKO0H6IdM6JFQ9XyIjOeO1CihDB2lhp HzNCCgN9cLw4m4bcT1voC4lZPWXxrmhHZZqutNWzT3jf6LnRjPdiRuMTGh1ZIj+BDBIE Txhz8CEoYDWCgu7Ql2JUGO1gQgYcBEHYRRYk5M7fGd7cfUXibpeuSpjBxEWQ/5kwf03B tZIj/w2Ur0BGvMyhhPghyYYaWHQ1+vCuvXN0ukGe6Vz/y0sPtJqLO1GucZHhrdu2dAAP AsrA== 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:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=WaLaWmqzSNmNiJqczhgiO4T48KRhGKoouD6uD1vGyCY=; b=1wLdoQp7QnnfzyxXBLJu29tgVfi0jLsRXffUXzkXwoiR4b44LiaHXU+0gHtttyOSUG 7H3y/J2TMd37DnDQ5WXSqk+v20TSVakI+PY80XWK+OcZ+S3l53ugJkf4hk4uDCfQCDuW 1i6SeQ+t6kGsejnjm8F+5UViwvTx17JHQl8aWwZS+d9kuRGFVe92d0cw3fDvnGfBanui dYMbfA1/oz7cJ5PZLiTUfzoC4BF5UxrmQt7FWSTjxVpSiiVDJ5Gn0+tx4bSV+8+4H/yK Os4J0lABT5LvitQ9fBh2rAzt6C+9aghYQ8aWDSfqNeNKch4Hp5Bo4kxIxUoW5YEHedbk JhgA== X-Gm-Message-State: AOAM5311zKMM7UMEeHJT5msS/yx++zn8OmCuyIUhFJRrlmC/R3jpHcJd aKfkIV1IQyBqP6cvXWPCW2E= X-Google-Smtp-Source: ABdhPJyFXEGG9fYbQJ1RLdam3io2TtLO8iP183C3zoYb6FkBsGhn1MXPBsTlC7kli1uI27ODmKSplA== X-Received: by 2002:ac2:5601:0:b0:472:11a6:8287 with SMTP id v1-20020ac25601000000b0047211a68287mr3744672lfd.440.1652454874848; Fri, 13 May 2022 08:14:34 -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 e9-20020a05651236c900b0047255d21159sm408089lfs.136.2022.05.13.08.14.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 May 2022 08:14:34 -0700 (PDT) Message-ID: Date: Fri, 13 May 2022 22:14:32 +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 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> <874k1wjjd8.fsf@localhost> From: Max Nikulin In-Reply-To: <874k1wjjd8.fsf@localhost> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2a00:1450:4864:20::132; envelope-from=manikulin@gmail.com; helo=mail-lf1-x132.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=1652454935; 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=WaLaWmqzSNmNiJqczhgiO4T48KRhGKoouD6uD1vGyCY=; b=boeWAPfwe02tbL3vvbUQTwaUGEHInIrfZyN8OujGLm2mKO5km20qv+tlG1Bb/B3DwBAYZZ OmjwYe0JAWI/RWIwHmQYOdHwo1ZSzHDgm2t1pwZtkw8yrXqTyFT6DHPMZB44VcCP8PmKDI 2btwDxYqWklJsbnDoCqDfJInvaGs13eRO7YUYKZIyBya0Ablc3MDIGt/vWpEfICFEdjiTD Tf6VzaM1Wka3qvmqFM9Ho9B13clhlRMA5HvMZYb64Fjaq7hrkT/FeLhLPlIz0HszRNT6dY ZQg6Rgtp529RwjyM2Xe2AwRIhb66tiRvXzvN1KMDlt2gH0trvYDn9a1Yeg8F4w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1652454935; a=rsa-sha256; cv=none; b=dCD9xIETvIf0Rob6iPBt/QqFhIvwxROYljvM4B4XwUhFvKEcAKMIn/QAeQgkFgu7xUvSoB u/m8ZW0RgBiit1H6KBfHpbSklgpvHVjz8wniVDPwm13KFny/1oJToeUXWhN1m03yR8jzcw MmXPDTQq5RSpP54kAfnZLZ4IC6bWzH0qCF4TLsLEzwJNAySefhzvnmgCAd0VQ/HwOsVmjb YJxnHkKzg1m7Oank76B0fPsz2ZBbbPwyRJGUPAbY4mpEK/HwHjazCiYDIOBNCzNGAAYZ5S ddlzfajGkG0g1Hea0rkaSsJsbDwn8lPfDUW3BVXIvuEZ1TxDRpSg2BlSOyYdbg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=jYeMVL0M; 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: 5.17 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=jYeMVL0M; 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: 1509E1531B X-Spam-Score: 5.17 X-Migadu-Scanner: scn0.migadu.com X-TUID: /5Ae18jpEXhu On 11/05/2022 20:20, Ihor Radchenko wrote: > Max Nikulin writes: > >>> + ;; 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)))))) >> >> I do not like repeating of `org-encode-time' but do not see another way >> till Emacs-29 will become the lowest supported version. > > This is fine. AFAIK, other parts of time handling code is full of conds > and pcases. I mean that before my patch there was single `encode-time' outside of `pcase', I replace `list' by `org-encode-time' inside each pattern. >>> + (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. > > Yes, the second version is rather hard to understand. The proper > solution would be writing (or using) some high-level time handling > library and then using it in Org. Then, we would not need to deal with > low-level time representations so frequently. From my point of view (cl-mapcar (lambda (value part) (if (and part (eq part timestamp?)) (+ n value) value)) time0 '(second minute hour day month year nil nil nil)) is better than the original code, but... Nicolas Goaziou to emacs-orgmode. [Patch] to correctly sort the items with emphasis marks in a list. Mon, 19 Apr 2021 18:08:17 +0200. https://list.orgmode.org/87r1j6b6ku.fsf@nicolasgoaziou.fr > > I stay away from CL as much as possible, otherwise newcomers will have > to learn two languages to start contributing, Elisp and CL (cl-loop, > ewww). CL is still necessary however, as we cannot use `seq' yet.