From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id UKtQHTiCMGEP5gAAgWs5BA (envelope-from ) for ; Thu, 02 Sep 2021 09:50:16 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id aEwPGTiCMGFqBgAA1q6Kng (envelope-from ) for ; Thu, 02 Sep 2021 07:50:16 +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 A152922A16 for ; Thu, 2 Sep 2021 09:50:15 +0200 (CEST) Received: from localhost ([::1]:38198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLhUD-0007jp-5W for larch@yhetil.org; Thu, 02 Sep 2021 03:50:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLhRS-0005kp-Un for emacs-orgmode@gnu.org; Thu, 02 Sep 2021 03:47:22 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]:42530) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mLhRR-00051O-Ac for emacs-orgmode@gnu.org; Thu, 02 Sep 2021 03:47:22 -0400 Received: by mail-lf1-x129.google.com with SMTP id t12so2162676lfg.9 for ; Thu, 02 Sep 2021 00:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/kondOf5O9EBDzxgRcR0hGJYmQC0Z4y6GAyMRo1Iw3c=; b=DNP4BqsH1QNrA/w+QL5Ej2oVjDS51fnqhlXjyaOyzBDVjQLDmsdF6CO9DCKTOCNwj+ vRW4eCcjrY89+I1xsD5aWfUJuD5JWnMJDnhs1PXz8U8YytSL2VzrROcCpgr45x94yN8a M752qVReJavH2oeXaV/N6KFIObVjlf+9DaCN3Xsp34txjhI+EHSYCeZj5DHVwPoYGQPD wDhLkdhr0o2p/yDP4JYmFFuDUA+jtvZxKpRfcHvdlKv9cK0ka8BgVYsg7HUNxnqseDY9 bMzsAiU3STFvObF9Tb/oxcYoOAgxCIyn4NoF9uNeUB82rnylHgQZ+KjL8t0X+buyMIh0 RNkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/kondOf5O9EBDzxgRcR0hGJYmQC0Z4y6GAyMRo1Iw3c=; b=drpCXLvOJdqD465/ALOjm/Qlb8EFCaG6i1KdEHQTUvklUllXNgFeygiUJ+xGxHv8HT RWx2h+nD2rykfqYLtcgO8xvtq6TVNGzpnoIDpBcHyYGVFcWf1LwVCrJl5jpCJEDRyISG echwLGGKMy7+48iAwUMixZNOPMQ/f1W39enUyKT7jHdcQquZ2o0IKQV6mScsNMAXE2nc VLkhxCzxuATFmTtv6TstAxsisN4gGzXVPe9aEl13tiE3Qh2vuL+B2pC9YxgaL3DvBOn9 VXx0JDLxzswsASbQLX+6bEMldOeC/2RN8UOpLxB3la7hRt3EE1Hzqw8zZl0xv5CewvLZ zF2Q== X-Gm-Message-State: AOAM533/eNo3vrwY+HKB2G8+oFg6if7jjip9uLUSu034WNyW59zRaWjU 0Oa2icbX3EchJrJCIPj0SoDhwwFUZ2gld5Bc78I= X-Google-Smtp-Source: ABdhPJzQreva6pGqQv4Fj73QvKOnife9uttlOOTJZYyGa0tVBqiKt8qFIVAvgiyx/cEUs0iHdBFA3tIu+ryytVINhAA= X-Received: by 2002:a05:6512:4005:: with SMTP id br5mr1618594lfb.560.1630568839130; Thu, 02 Sep 2021 00:47:19 -0700 (PDT) MIME-Version: 1.0 References: <87wnosb9rc.fsf@nicolasgoaziou.fr> <87k0k1oh05.fsf@gmail.com> <87zgsx5upu.fsf@nicolasgoaziou.fr> In-Reply-To: <87zgsx5upu.fsf@nicolasgoaziou.fr> From: Anders Johansson Date: Thu, 2 Sep 2021 09:47:07 +0200 Message-ID: Subject: Re: [PATCH] Fix bug assuming canonical duration units in org-agenda-format-items To: Nicolas Goaziou Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2a00:1450:4864:20::129; envelope-from=mejlaandersj@gmail.com; helo=mail-lf1-x129.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, 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: , Cc: org-mode-email , Timothy Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1630569015; 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=/kondOf5O9EBDzxgRcR0hGJYmQC0Z4y6GAyMRo1Iw3c=; b=BxsZwGgPcJW9/iTL/3ERx8EDB6Ki6oFvpzmfAljbRHnutSKjNfL88WcvW3tc08+8lFiHDG AKHVNd5srqcuaWxLDFcrCpR6ZPd5n05FVyLemSDVKDNZUVnswmUtGU4Cfc/1Rbg2BOFk1P V5GywF0qu9JpLPOGKqWR2nQ/dO3Ganij+6ac9JBrvZSxVpmLsYqNpVDkyGZNAzj7OnCyhv Faai9uVZqv1mMGIJpxbc3OfmEr8OfXYIgd9R+IjdH+uwUHmWvywOj+XnYHHYiTbwiDNEXJ 2YzH0xlb7QJV41NBkxy59uJvEOebAYd5wX5UUye0kmGrpV+Rb0ATGUCYXmFLvw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1630569015; a=rsa-sha256; cv=none; b=eCfozEz7dcwem/bdLo/z6Cn0ErF6Tgu0Vh6wuow1ymKsqAcM2T9yqFnR0Z0HYje1ZwEzOG mFxPj5DRd/PIJrXzImEK8nFz8QWTMAEyZiDXsue472jnDVHhZZk2D/7x6+OlpZGNaem8+m iMjzfrnNMnFmEQcmX2k205/5hAppTC41+X+9Z6H4LxzWa91A9ZJpWIHpenFgSRX1/B6G57 eKSD98FyGxVId4ShctALNhJtpSIl17wet3pws1OUMJbN4JLqwZSJEIUkdvVwKRO1/5s1W5 nO+V3o3rbMT/D8dc6LC7X1/KJ4AisSFvPG6U86MZW/+8E9KRinDR2kmnkCbShA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=DNP4BqsH; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (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-Migadu-Spam-Score: -1.32 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=DNP4BqsH; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (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-Migadu-Queue-Id: A152922A16 X-Spam-Score: -1.32 X-Migadu-Scanner: scn1.migadu.com X-TUID: nb5boIXOyveg > >> I think a proper fix would be to change `org-duration-from-minutes' so > >> it removes any unknown unit from what is provided from fmt or > >> `org-duration-format', and defaults to (special . h:mm) if nothing is > >> left. > >> > >> WDYT? > >> > > Perhaps. I don't understand `org-duration-from-minutes` well enough to > > change it. > > You don't really need to understand it. I suggest using a filter as the > very first step of the function. > > > I guess the stripping of unknown units from fmt or > > `org-duration-format` would then have to compare either against > > `org-duration-units` or `org-duration-canonical-units` depending on > > the canonical argument. > > Exactly. > > > Regards, > -- > Nicolas Goaziou Included is a patch for the filtering (I assumed cl-intersection was reasonable to use since cl-lib is a requirement). However, I do not think this is enough, since it can cause quite unexpected results when canonical is used without specifying the format, Hence, I do think the previous patch should also be applied. For my case, org-duration-format is (("m") ("w") ("d") (special . h:mm)). This call to org-duration-from-minutes (like in org-agenda-format-item): (org-duration-from-minutes MINUTES nil t) will then result in a full format amounting to (("d")), (since "special" is not part of the canonical units), which is hardly what is expected for the agenda. Best, Anders Johansson [PATCH] Ensure valid duration format in org-duration-from-minutes Filter out any elements of the duration format that is not in org-duration-units or org-duration-canonical-units. --- lisp/org-duration.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lisp/org-duration.el b/lisp/org-duration.el index e627d0936..eb4b6075f 100644 --- a/lisp/org-duration.el +++ b/lisp/org-duration.el @@ -314,13 +314,19 @@ (defun org-duration-from-minutes (minutes &optional fmt canonical) "Return duration string for a given number of MINUTES. Format duration according to `org-duration-format' or FMT, when -non-nil. +non-nil. Invalid units in the duration format are discarded. When optional argument CANONICAL is non-nil, ignore `org-duration-units' and use standard time units value. Raise an error if expected format is unknown." - (pcase (or fmt org-duration-format) + (pcase (cl-intersection + (or fmt org-duration-format) + (if canonical + org-duration-canonical-units + org-duration-units) + :key #'car + :test #'equal) (`h:mm (format "%d:%02d" (/ minutes 60) (mod minutes 60))) (`h:mm:ss -- 2.33.0