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#71572: [PATCH] seconds-to-string-approximate Date: Sat, 7 Dec 2024 12:52:01 -0500 Message-ID: References: <86r0cpicwt.fsf@gnu.org> <86msmxafog.fsf@gnu.org> <3530cd89-b5a2-4b25-95bf-1896c8ee4aef@cs.ucla.edu> <8CC4B1BB-B56A-4C3E-8B51-0E2D5B65C296@gmail.com> <86jzcbir3c.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_E2DDFD1A-DDF1-4FCA-B0A4-9BD9B03E4C0E" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26435"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Adam Porter , 71572@debbugs.gnu.org, Jonas Bernoulli , Paul Eggert To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 07 18:54:23 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 1tJz0X-0006hw-Um for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 07 Dec 2024 18:54:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJz0G-0007C5-AG; Sat, 07 Dec 2024 12:54:04 -0500 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 1tJz0E-0007Bw-ST for bug-gnu-emacs@gnu.org; Sat, 07 Dec 2024 12:54:03 -0500 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 1tJz0E-0007Qt-J3 for bug-gnu-emacs@gnu.org; Sat, 07 Dec 2024 12:54:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:Date:Mime-Version:From:To:Subject; bh=9OKXykMuNW3FsRwAJljdhhoTXghqbmXZiyIKzq54xEc=; b=rS5urnzX/SbRi0TVg/KmscduFrW403aYBdO6oVc5IE3vMH1ie6eDtFZYaZklh8ahZUe1inpLiIJoRaxkjOc9e09q6l3HrKSYPLG+GjPvyrTXejYMcXXofKydXipcrhYpReE4tPpX+LBHpNwvf76Z76a2UPgAgErXkJxgWdR04duCHjkpE/zJV3ZH56oHC0RQSgoRXtNc2GigWOl+aKZRIo3zqeQym+cpWQNpLO5+J5LilGTRvVqiaGHyc2h1yBuRyI4aYBwEYMcDM0FhQPSW28JZK9HbCDaKZER8L0jYMFvmfpGYZ9XFx13V2lK9TEXnGTvq+MNIzL9rSV9m8crDwQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tJz0E-00026E-6I for bug-gnu-emacs@gnu.org; Sat, 07 Dec 2024 12:54:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: JD Smith Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 07 Dec 2024 17:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71572 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 71572-submit@debbugs.gnu.org id=B71572.17335939988007 (code B ref 71572); Sat, 07 Dec 2024 17:54:02 +0000 Original-Received: (at 71572) by debbugs.gnu.org; 7 Dec 2024 17:53:18 +0000 Original-Received: from localhost ([127.0.0.1]:48424 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tJyzW-000254-0x for submit@debbugs.gnu.org; Sat, 07 Dec 2024 12:53:18 -0500 Original-Received: from mail-il1-f179.google.com ([209.85.166.179]:47482) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tJyzS-00024t-F3 for 71572@debbugs.gnu.org; Sat, 07 Dec 2024 12:53:16 -0500 Original-Received: by mail-il1-f179.google.com with SMTP id e9e14a558f8ab-3a816cc9483so11568255ab.3 for <71572@debbugs.gnu.org>; Sat, 07 Dec 2024 09:53:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733593934; x=1734198734; darn=debbugs.gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=9OKXykMuNW3FsRwAJljdhhoTXghqbmXZiyIKzq54xEc=; b=dg3l8oJHNjWU5vuuX+l98+W0Yh+OvIZnMM+IiJi9Pf3op97L1HwiqG3oU7q1PzHmAS jNApCO+QJ0nufcYFzX7sOYt9k4t89PLNIyj3XMCYP5rT5jgwR9vVgf2jVvHSNRQCJ6dn f1k2jSKhOkb8X4yw6pdcAnb1A/SFxA69iz2LpEEkllSj4rwghZmbozhiVuqq74qA1rOK IkG25Z4l7P8MpucFcz3Py3z6GyBev5XWybLNcMzKWFI7icSbnLhZUIzKvt+ItuRFyE8m XyMHHsqm9gOQ5EYDHoKdX74arMYEJKSy2w4HTBGuFcGtsHYP/F9wWctbjzlNTqHIfRq1 LL0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733593934; x=1734198734; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9OKXykMuNW3FsRwAJljdhhoTXghqbmXZiyIKzq54xEc=; b=YgDy/bssxUqveMe993gX408JjMAAnelOet7npgs1zoDduo9lXvZO3PuK8BGcJn5sJT zE1z9aqOR+NGtwvBp+8xNxUdulsxe8aNa+NhoK38TmQ+TOoVKzrqehEGjKZiXYv0KYFn ngqk/ulyeQbptfivk/Zmw34yad8MRRCkl9u+LHUwq9LQEwcvzkURpftIU0GRN3eMKrpY f76DXn6GXMyjbg+7gjzx+yXdkKfZ3WCEGjDVd527dc2QKUurwjSMmGMA1e8rGTp8zN8c NlQdpvDv0EPZ+J1HVmEVzvt9Cbsss8GOAIv4oWiQJ0taRce2x4WY2CbKcgVlbuPpS5WA tQVQ== X-Gm-Message-State: AOJu0YzGurzdfcKqlhZpqePI/46EhRImEYhA7U9JOo31CSI+Wsv68B3Z 4KW5FFjkb72s6NaEaMvRtIUbhExn5+EJRbEftn1+PI++9PTNDrn1w7HCzA== X-Gm-Gg: ASbGncslzC+VIuAMEgRGVlGjKFRFgzhzV4b7SbTLZWf4mQaFaE4iRsKcxwgbjlJ8Fxn anc2atam7fEQe7jiGhaClf6eNud0PLNMBpNHP8+NWn6inVlZNUhD7TrDk0UGxRTsCLsa4Lk9w81 PDI9ea9H+BlMrntT51DXpStTdji/W4iFBMqQCH/o2LwZTKjHujRW1Zxx+0LYFbDtMenREsaLAoX jjndvMFXpw9XdC5AWjxDx5+AXx1V3FoUYBk8HLPTpdYI2NNyBz53GGXNa8VaBdRxg== X-Google-Smtp-Source: AGHT+IGP/L8fZivdBEix+8TW34neJUrHuKc/ibhfO9368cUF15FTE7r42vY6cTE9eoXmhM912sVWWw== X-Received: by 2002:a05:6e02:190a:b0:3a7:7ee3:108d with SMTP id e9e14a558f8ab-3a811e4a952mr84644705ab.23.1733593933750; Sat, 07 Dec 2024 09:52:13 -0800 (PST) Original-Received: from smtpclient.apple ([12.1.245.2]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3a817b273e3sm8655945ab.62.2024.12.07.09.52.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Dec 2024 09:52:12 -0800 (PST) In-Reply-To: <86jzcbir3c.fsf@gnu.org> X-Mailer: Apple Mail (2.3774.600.62) 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:296588 Archived-At: --Apple-Mail=_E2DDFD1A-DDF1-4FCA-B0A4-9BD9B03E4C0E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Dec 7, 2024, at 8:02=E2=80=AFAM, Eli Zaretskii = wrote: >=20 >> From: JD Smith >> Date: Sat, 30 Nov 2024 13:58:52 -0500 >> Cc: Eli Zaretskii , >> Adam Porter , >> jonas@bernoul.li, >> Paul Eggert >>=20 >> I was recently reminded of the need for a more capable = seconds-to-string. =20 >>=20 >> Anyone have any additional comments on this proposed patch? If not, = I'd suggest someone with access >> merges. >=20 > A few minor nits below, and then we can install: Thanks. Updated patch below. --Apple-Mail=_E2DDFD1A-DDF1-4FCA-B0A4-9BD9B03E4C0E Content-Disposition: attachment; filename=0001-seconds-to-string-new-optional-arguments-for-readabl.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-seconds-to-string-new-optional-arguments-for-readabl.patch" Content-Transfer-Encoding: quoted-printable =46rom=2099f52d767e67d5ce929a2696749b3db635bd302d=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20JD=20Smith=20= <93749+jdtsmith@users.noreply.github.com>=0ADate:=20Thu,=2011=20Jul=20= 2024=2016:24:17=20-0400=0ASubject:=20[PATCH]=20seconds-to-string:=20new=20= optional=20arguments=20for=20readable=0A=20strings=0A=0A---=0A=20= doc/lispref/os.texi=20=20=20=20=20=20=20=20|=20=206=20+++=0A=20etc/NEWS=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20=207=20++++=0A=20= lisp/calendar/time-date.el=20|=2081=20= ++++++++++++++++++++++++++++++++++++--=0A=203=20files=20changed,=2090=20= insertions(+),=204=20deletions(-)=0A=0Adiff=20--git=20= a/doc/lispref/os.texi=20b/doc/lispref/os.texi=0Aindex=20= 3ba3da459bf..ac9d5acdf3d=20100644=0A---=20a/doc/lispref/os.texi=0A+++=20= b/doc/lispref/os.texi=0A@@=20-2155,6=20+2155,12=20@@=20Time=20= Calculations=0A=20structure.=20=20For=20instance,=20the=20120th=20day=20= in=202004=20is=20April=2029th.=0A=20@end=20defun=0A=20=0A+@defun=20= seconds-to-string=20delay=20&optional=20readable=20abbrev=20precision=0A= +Return=20a=20string=20describing=20a=20given=20@var{delay}=20(in=20= seconds).=20=20Optional=0A+arguments=20can=20be=20used=20to=20configure=20= a=20human=20readable=20delay=20using=20various=0A+formats.=20=20For=20= example,=20a=20delay=20of=209861.5=20seconds=20with=20@var{readable}=20= set=0A+to=20the=20symbol=20@code{expanded}=20returns=20@samp{2=20hours=20= 44=20minutes}.=0A+=0A=20@node=20Timers=0A=20@section=20Timers=20for=20= Delayed=20Execution=0A=20@cindex=20timers=0Adiff=20--git=20a/etc/NEWS=20= b/etc/NEWS=0Aindex=20f10f9ae4d65..1fd2a9404bb=20100644=0A---=20= a/etc/NEWS=0A+++=20b/etc/NEWS=0A@@=20-30,6=20+30,13=20@@=20applies,=20= and=20please=20also=20update=20docstrings=20as=20needed.=0A=20=0C=0A=20*=20= Changes=20in=20Emacs=2031.1=0A=20=0A+**=20Time=20&=20Date=0A+=0A++++=0A= +***=20'seconds-to-string'=20includes=20new=20formatting=20options.=0A= +Options=20are=20provided=20to=20produce=20human-readable=20delay=20= strings=20in=20a=0A+variety=20of=20formats,=20for=20example=20"6=20= months=203=20weeks"=20or=20"5m=2052.5s".=0A+=0A=20=0C=0A=20*=20Editing=20= Changes=20in=20Emacs=2031.1=0A=20=0Adiff=20--git=20= a/lisp/calendar/time-date.el=20b/lisp/calendar/time-date.el=0Aindex=20= eca80f1e8b6..60573f814ac=20100644=0A---=20a/lisp/calendar/time-date.el=0A= +++=20b/lisp/calendar/time-date.el=0A@@=20-409,11=20+409,84=20@@=20= seconds-to-string=0A=20=20=20=20=20=20=20=20=20(list=20(*=203600=2024=20= 400)=20"d"=20(*=203600.0=2024.0))=0A=20=20=20=20=20=20=20=20=20(list=20= nil=20"y"=20(*=20365.25=2024=203600)))=0A=20=20=20"Formatting=20used=20= by=20the=20function=20`seconds-to-string'.")=0A+=0A+(defvar=20= seconds-to-string-readable=0A+=20=20`(("Y"=20"year"=20=20=20"years"=20=20= =20,(round=20(*=2060=2060=2024=20365.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=20= 7))=0A+=20=20=20=20("d"=20"day"=20=20=20=20"days"=20=20=20=20,(*=2060=20= 60=2024))=0A+=20=20=20=20("h"=20"hour"=20=20=20"hours"=20=20=20,(*=2060=20= 60))=0A+=20=20=20=20("m"=20"minute"=20"minutes"=2060)=0A+=20=20=20=20= ("s"=20"second"=20"seconds"=201))=0A+=20=20"Formatting=20used=20by=20the=20= function=20`seconds-to-string'=20with=20READABLE=20set.=0A+The=20format=20= is=20an=20alist,=20with=20string=20keys=20ABBREV-UNIT,=20and=20elements=20= like:=0A+=0A+=20=20(ABBREV-UNIT=20UNIT=20UNIT-PLURAL=20SECS)=0A+=0A= +where=20UNIT=20is=20a=20unit=20of=20time,=20ABBREV-UNIT=20is=20the=20= abreviated=20form=20of=0A+UNIT,=20UNIT-PLURAL=20is=20the=20plural=20form=20= of=20UNIT,=20and=20SECS=20is=20the=20number=20of=0A+seconds=20per=20= UNIT.")=0A+=0A=20;;;###autoload=0A-(defun=20seconds-to-string=20(delay)=0A= -=20=20;;=20FIXME:=20There's=20a=20similar=20(tho=20fancier)=20function=20= in=20mastodon.el!=0A-=20=20"Convert=20the=20time=20interval=20in=20= seconds=20to=20a=20short=20string."=0A-=20=20(cond=20((>=200=20delay)=20= (concat=20"-"=20(seconds-to-string=20(-=20delay))))=0A+(defun=20= seconds-to-string=20(delay=20&optional=20readable=20abbrev=20precision)=0A= +=20=20"Convert=20time=20interval=20DELAY=20(in=20seconds)=20to=20a=20= string.=0A+By=20default,=20the=20returned=20string=20is=20formatted=20as=20= a=20float=20in=20the=20smallest=0A+unit=20from=20the=20variable=20= `seconds-to-string'=20that=20is=20longer=20than=20DELAY,=0A+and=20a=20= precision=20of=20two.=20=20If=20READABLE=20is=20non-nil,=20convert=20= DELAY=20into=20a=0A+readable=20string,=20using=20the=20information=20= provided=20in=20the=20variable=0A+`seconds-to-string-readable'.=20=20If=20= it=20is=20the=20symbol=20`expanded',=20use=20two=0A+units=20to=20= describe=20DELAY,=20if=20appropriate.=20=20E.g.=20\"1=20hour=2032=20= minutes\".=0A+If=20ABBREV=20is=20non-nil,=20abbreviate=20the=20readable=20= units.=20=20If=20PRECISION=20is=20a=0A+whole=20number,=20round=20the=20= value=20associated=20with=20the=20smallest=20displayed=0A+unit=20to=20= that=20many=20digits=20after=20the=20decimal.=20=20If=20it=20a=20= non-negative=20float=0A+less=20than=201.0,=20round=20to=20that=20value."=0A= +=20=20(cond=20((<=20delay=200)=0A+=09=20(concat=20"-"=20= (seconds-to-string=20(-=20delay)=20readable=20precision)))=0A+=20=20=20=20= =20=20=20=20(readable=0A+=20=20=20=20=20=20=20=20=20(let*=20((stsa=20= seconds-to-string-readable)=0A+=09=09(expanded=20(eq=20readable=20= 'expanded))=0A+=09=09digits=0A+=09=09(round-to=20(cond=20((wholenump=20= precision)=0A+=09=09=09=09=20(setq=20digits=20precision)=0A+=09=09=09=09=20= (expt=2010=20(-=20precision)))=0A+=09=09=09=09((and=20(floatp=20= precision)=20(<=20precision=201.))=0A+=09=09=09=09=20(setq=20digits=20(-=20= (floor=20(log=20precision=2010))))=0A+=09=09=09=09=20precision)=0A+=09=09= =09=09(t=20(setq=20digits=200)=201)))=0A+=09=09(dformat=20(if=20(>=20= digits=200)=20(format=20"%%0.%df"=20digits)))=0A+=09=09(padding=20(if=20= abbrev=20""=20"=20"))=0A+=09=09here=20cnt=20cnt-pre=20here-pre=20= cnt-val)=0A+=09=20=20=20(if=20(=3D=20(round=20delay=20round-to)=200)=0A+=09= =20=20=20=20=20=20=20(format=20"0%s"=20(if=20abbrev=20"s"=20"=20= seconds"))=0A+=09=20=20=20=20=20(while=20(and=20(setq=20here=20(pop=20= stsa))=20stsa=0A+=09=09=09=20(<=20(/=20delay=20(nth=203=20here))=201)))=0A= +=09=20=20=20=20=20(or=20(and=0A+=09=09=20=20expanded=20stsa=20=09;=20= smaller=20unit=20remains=0A+=09=09=20=20(progn=0A+=09=09=20=20=20=20= (setq=0A+=09=09=20=20=20=20=20here-pre=20here=20here=20(car=20stsa)=0A+=09= =09=20=20=20=20=20cnt-pre=20(floor=20(/=20(float=20delay)=20(nth=203=20= here-pre)))=0A+=09=09=20=20=20=20=20cnt=20(round=0A+=09=09=09=20=20(/=20= (-=20(float=20delay)=20(*=20cnt-pre=20(nth=203=20here-pre)))=0A+=09=09=09= =20=20=20=20=20(nth=203=20here))=0A+=09=09=09=20=20round-to))=0A+=09=09=20= =20=20=20(if=20(>=20cnt=200)=20t=20(setq=20cnt=20cnt-pre=20here=20= here-pre=20here-pre=20nil))))=0A+=09=09=20(setq=20cnt=20(round=20(/=20= (float=20delay)=20(nth=203=20here))=20round-to)))=0A+=09=20=20=20=20=20= (setq=20cnt-val=20(*=20cnt=20round-to))=0A+=09=20=20=20=20=20(cl-labels=0A= +=09=09=20((unit=20(val=20here)=0A+=09=09=20=20=20=20(cond=20(abbrev=20= (car=20here))=0A+=09=09=09=20=20((<=3D=20(floor=20val)=201)=20(nth=201=20= here))=0A+=09=09=09=20=20(t=20(nth=202=20here)))))=0A+=09=20=20=20=20=20=20= =20(concat=0A+=09=09(when=20here-pre=0A+=09=09=20=20(concat=20= (number-to-string=20cnt-pre)=20padding=0A+=09=09=09=20=20(unit=20(*=20= cnt-pre=20round-to)=20here-pre)=20"=20"))=0A+=09=09(if=20(and=20(>=20= digits=200)=0A+=09=09=09=20(>=20(-=20cnt-val=20(floor=20cnt-val))=200.))=0A= +=09=09=20=20=20=20(format=20dformat=20cnt-val)=0A+=09=09=20=20= (number-to-string=20(floor=20cnt-val)))=0A+=09=09padding=20(unit=20= cnt-val=20here))))))=0A=20=20=20=20=20=20=20=20=20((=3D=200=20delay)=20= "0s")=0A=20=20=20=20=20=20=20=20=20(t=20(let=20((sts=20= seconds-to-string)=20here)=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (while=20(and=20(car=20(setq=20here=20(pop=20sts)))=0A--=20=0A2.45.2=0A=0A= --Apple-Mail=_E2DDFD1A-DDF1-4FCA-B0A4-9BD9B03E4C0E--