From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: JD Smith Newsgroups: gmane.emacs.bugs Subject: bug#71573: [PATCH] seconds-to-string-approximate Date: Sat, 15 Jun 2024 13:24:00 -0400 Message-ID: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_DF256C8E-CD44-4309-983F-3A06CCC42DF6" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2431"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Adam Porter , jonas@bernoul.li To: 71573@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 15 19:25:30 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sIX9d-0000U7-TM for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 15 Jun 2024 19:25:30 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sIX9M-0004cr-0O; Sat, 15 Jun 2024 13:25:12 -0400 Original-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 1sIX9C-0004bA-FV for bug-gnu-emacs@gnu.org; Sat, 15 Jun 2024 13:25:04 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sIX9C-0008Iw-6W for bug-gnu-emacs@gnu.org; Sat, 15 Jun 2024 13:25:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sIX9C-0004CL-Uw for bug-gnu-emacs@gnu.org; Sat, 15 Jun 2024 13:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: JD Smith Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 15 Jun 2024 17:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71573 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.171847226616012 (code B ref -1); Sat, 15 Jun 2024 17:25:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Jun 2024 17:24:26 +0000 Original-Received: from localhost ([127.0.0.1]:34684 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sIX8b-0004A8-CU for submit@debbugs.gnu.org; Sat, 15 Jun 2024 13:24:25 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:40980) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sIX8X-00049h-Vl for submit@debbugs.gnu.org; Sat, 15 Jun 2024 13:24:24 -0400 Original-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 1sIX8W-0004Ug-Sb for bug-gnu-emacs@gnu.org; Sat, 15 Jun 2024 13:24:20 -0400 Original-Received: from mail-yw1-x112f.google.com ([2607:f8b0:4864:20::112f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sIX8S-0008FK-63 for bug-gnu-emacs@gnu.org; Sat, 15 Jun 2024 13:24:17 -0400 Original-Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-6316253dc2aso25853447b3.0 for ; Sat, 15 Jun 2024 10:24:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718472254; x=1719077054; darn=gnu.org; h=to:cc:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=tEgXJ0zt2kVwQ7fz1Bay67qQEr2ZrCy6pptRY+wP0hA=; b=DNxRcji5wZt4+zQpLfoVYJJIqIIGVqe8X5vgMBh6fiJHwkNYYvCQL2OeMuS1atN9Z9 Qm/ZH7lTYDJgJiHagQQhJfSd3i422idtV6ZN/BDn+FOj28x1UR8PWcwlf7IRQrZu47wX 2y4YgoR7z0y3cEuj/LRjrFMJupKK52Vis8dnI32hRtmCCpA4OjKSqthzZ00d9/XDqINP rJQzCA22SUpMR6ObM9TP3lZU/78oc1UVFXErjkoFJk+gvWviVxjMshYs59W5cZvef0iv ITFhmd4CuIIsZEQErU6XEl+stvtF+PoUBXcdC8ofOS/mV4ug1pj24ePfMQ47HSnv6rfN 6clQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718472254; x=1719077054; h=to:cc:date:message-id:subject:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=tEgXJ0zt2kVwQ7fz1Bay67qQEr2ZrCy6pptRY+wP0hA=; b=Zkh7FeTH+t5CgVn21N8uZART60gN7sG3lSWKlIYLlPommk9pa2TbfJsHcf/CRnew+g eRarAQURdL/HH87YwU/GWqGO3T/WOprURV2SuKS5K1ZHmPmfxzWov8mH1AK56wlHA6pw uUHd8qbeWPlQT7trwCVSqu6jkhD9KHbpDZvg0tDKFkXrbhNU5EaoQseVxb0bYvcsA5Tv 02lfUZ11KHrH00skJ3aX/+nFLS45Mif5b8GUWacgVmVaLVB8LTRpj/y6ky9EcXdHjM1m 6AkFHvcWsWhchNVdDCzuFQEfN67QtgVRX7Fvgp2vvbfGqzatmdxzA0djeriOHMNnoE5W OTQA== X-Gm-Message-State: AOJu0Yw6Kd+fdoCssnJmlWNdL+k/IBkodbAblpY3hcfe6xV6YFkUHg7w t5kxWnSY6s023vZZBlh3hGUYAdiaaQtukp82lilTCa7R3sundupb9SLtqw== X-Google-Smtp-Source: AGHT+IEaxK25QSCv+U887olBduaQkZN2Nfj4caCfqp4QNTlT9aorv5m71aLbJr7wJORORD0PRQ1VgQ== X-Received: by 2002:a81:b554:0:b0:630:c168:d23d with SMTP id 00721157ae682-632226609acmr46361427b3.21.1718472253532; Sat, 15 Jun 2024 10:24:13 -0700 (PDT) Original-Received: from smtpclient.apple (cm-24-53-187-34.buckeyecom.net. [24.53.187.34]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b2a5eb4a23sm33956936d6.75.2024.06.15.10.24.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Jun 2024 10:24:12 -0700 (PDT) X-Mailer: Apple Mail (2.3774.600.62) Received-SPF: pass client-ip=2607:f8b0:4864:20::112f; envelope-from=jdtsmith@gmail.com; helo=mail-yw1-x112f.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:287302 Archived-At: --Apple-Mail=_DF256C8E-CD44-4309-983F-3A06CCC42DF6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 A very useful and widely used time operation is to approximate a given = delay or age (in seconds) using a human-readable unit =E2=80=94 think "2 = hours", "5 days", "3 weeks", or "7 months". We have = `seconds-to-string', but it provides more precision than is often = required, skips some meaningful "human readable" duration units like = weeks and months, and uses abbreviated units exclusively. =20 For those familiar with magit, the `magit--age' function has provided = this capability for quite some time (e.g. for short commit age), and = other packages have adapted it. It would be useful to have a version in = core. This patch provides a `seconds-to-string-approximate' function based = loosely on `magit--age' and `seconds-to-string'. It allows using = abbreviated or full units, and can optionally round to the nearest = half-unit. --Apple-Mail=_DF256C8E-CD44-4309-983F-3A06CCC42DF6 Content-Disposition: attachment; filename=seconds-to-string-approximate.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="seconds-to-string-approximate.patch" Content-Transfer-Encoding: quoted-printable diff=20--git=20a/lisp/calendar/time-date.el=20= b/lisp/calendar/time-date.el=0Aindex=20eca80f1e8b6..079001bafe2=20100644=0A= ---=20a/lisp/calendar/time-date.el=0A+++=20b/lisp/calendar/time-date.el=0A= @@=20-420,6=20+420,37=20@@=20seconds-to-string=0A=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(<=3D=20(car=20= here)=20delay)))=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20(concat=20= (format=20"%.2f"=20(/=20delay=20(car=20(cddr=20here))))=20(cadr=20= here))))))=0A=20=0A+(defvar=20seconds-to-string-approximate=0A+=20=20= `(("Y"=20"year"=20=20=20"years"=20=20=20,(round=20(*=2060=2060=2024=20= 365.2425)))=0A+=20=20=20=20("M"=20"month"=20=20"months"=20=20,(round=20= (*=2060=2060=2024=2030.436875)))=0A+=20=20=20=20("w"=20"week"=20=20=20= "weeks"=20=20=20,(*=2060=2060=2024=207))=0A+=20=20=20=20("d"=20"day"=20=20= =20=20"days"=20=20=20=20,(*=2060=2060=2024))=0A+=20=20=20=20("h"=20= "hour"=20=20=20"hours"=20=20=20,(*=2060=2060))=0A+=20=20=20=20("m"=20= "minute"=20"minutes"=2060)=0A+=20=20=20=20("s"=20"second"=20"seconds"=20= 1))=0A+=20=20"Formatting=20used=20by=20the=20function=20= `seconds-to-string-approximate'.")=0A+;;;###autoload=0A+(defun=20= seconds-to-string-approximate=20(delay=20&optional=20abbreviate=20half)=0A= +=20=20"Convert=20the=20time=20interval=20DELAY=20in=20seconds=20to=20a=20= string=20approximation.=0A+Abbreviate=20the=20units=20if=20ABBREVIATE=20= is=20non-nil.=20=20If=20HALF=20is=20non-nil,=0A+round=20to=20the=20= nearest=20half-unit,=20otherwise=20round=20to=20the=20nearest=20unit."=0A= +=20=20(cond=20((>=200=20delay)=0A+=20=20=20=20=20=20=20=20=20(concat=20= "-"=20(seconds-to-string-approximate=20(-=20delay)=20abbreviate=20= half)))=0A+=20=20=20=20=20=20=20=20((=3D=20(round=20delay=20(if=20half=20= 0.5=201.))=200)=0A+=20=20=20=20=20=20=20=20=20(format=20"0%s"=20(if=20= abbreviate=20"s"=20"=20seconds")))=0A+=20=20=20=20=20=20=20=20(t=20(let=20= ((stsa=20seconds-to-string-approximate)=20here=20cnt)=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20(while=20(and=20(setq=20here=20(pop=20stsa))=20stsa=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20(<=20(/=20delay=20(nth=203=20here))=201)))=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20(setq=20cnt=20(round=20(/=20(float=20delay)=20(nth=203=20= here))=20(if=20half=200.5=201.)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20(concat=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20(let=20((c=20(if=20= half=20(/=20cnt=202)=20cnt)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(if=20(>=20c=200)=20(number-to-string=20c)=20""))=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(if=20(and=20half=20(=3D=20(mod=20cnt=202)=20= 1))=20"=C2=BD"=20"")=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20(if=20= abbreviate=20""=20"=20")=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (cond=20(abbreviate=20(car=20here))=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20((<=3D=20cnt=20(if=20half=202=201))=20(nth=201=20= here))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(t=20= (nth=202=20here))))))))=0A+=0A=20(defun=20date-days-in-month=20(year=20= month)=0A=20=20=20"The=20number=20of=20days=20in=20MONTH=20in=20YEAR."=0A= =20=20=20(unless=20(and=20(numberp=20month)=20(<=3D=201=20month=2012))=0A= --Apple-Mail=_DF256C8E-CD44-4309-983F-3A06CCC42DF6--