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: Thu, 11 Jul 2024 17:01:05 -0400 Message-ID: <8CC4B1BB-B56A-4C3E-8B51-0E2D5B65C296@gmail.com> References: <86r0cpicwt.fsf@gnu.org> <86msmxafog.fsf@gnu.org> <3530cd89-b5a2-4b25-95bf-1896c8ee4aef@cs.ucla.edu> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_81DD6890-84BD-4B48-ACF9-160C3B7CA8C1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12512"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Adam Porter , Eli Zaretskii , jonas@bernoul.li, Paul Eggert To: 71572@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 11 23:03:31 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 1sS0wr-0002yP-Ch for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Jul 2024 23:03:29 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sS0wY-0004on-2o; Thu, 11 Jul 2024 17:03:10 -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 1sS0wS-0004o1-7H for bug-gnu-emacs@gnu.org; Thu, 11 Jul 2024 17:03: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 1sS0wR-0004CA-LW for bug-gnu-emacs@gnu.org; Thu, 11 Jul 2024 17:03:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sS0wQ-0003HV-F6 for bug-gnu-emacs@gnu.org; Thu, 11 Jul 2024 17:03: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: Thu, 11 Jul 2024 21:03: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.172073174812566 (code B ref 71572); Thu, 11 Jul 2024 21:03:02 +0000 Original-Received: (at 71572) by debbugs.gnu.org; 11 Jul 2024 21:02:28 +0000 Original-Received: from localhost ([127.0.0.1]:52665 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sS0vr-0003Gb-AE for submit@debbugs.gnu.org; Thu, 11 Jul 2024 17:02:28 -0400 Original-Received: from mail-qk1-f175.google.com ([209.85.222.175]:45405) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sS0vo-0003GJ-9v for 71572@debbugs.gnu.org; Thu, 11 Jul 2024 17:02:26 -0400 Original-Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-79f1be45ca8so77872585a.3 for <71572@debbugs.gnu.org>; Thu, 11 Jul 2024 14:02:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720731678; x=1721336478; 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=KgmHAgOnDm7ysNGnxm5GAy0Jz8V+cO6Eemesz8gUH0w=; b=jyVZkVDtMjLGsWPy/BztgPZODpvCjGWBx0XR/WESbSoqAEtwidHEPcmistXad8v+HO bbDZAEY9hwBxWrcqOzDUGVFruJyiKoYR73z+voAvlE+MmbiI9D8d7fXhnpacOJSFCVQz th0SnaBNGVqPZE8HR8wL+5DsD1sNBYaI2gvvbsdmAlNfns5d6ORwjJl2jRK5Y3MHiQWr FY0km0zPb+ARr8vnPm80d377lvji5vDwUcV0judTyn+eaL5KJmz8iOjImGOGyZP2TKlp ZOge1obvSh+LWgzDJBZng9gghR26L5DE0pOtkXJUTdOmYY0QuSLKMFF1GM+wj7vwpE1S mRxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720731678; x=1721336478; 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=KgmHAgOnDm7ysNGnxm5GAy0Jz8V+cO6Eemesz8gUH0w=; b=iccNdeBGRR4WbPs9JohCjMZ6jJKqz/5EohDOVdX7UiOXhGoGW8PHk8y+1eCQuTYVN8 ZBNho4rZJNll5l00obqYc8uhJ03n729uH2y8+OjePbmgGzMiD5ZBm937b+X1YCMBDckN KHz408myyQ4s/bMm479+AhD3+u1KzbbkzE+3LGpKysa3ve4S/CrNx/KYm33VXJE7MCV6 l0u13atUZB1f8MknrysGJ3CSnHurMyrQiW2DUzAynVpTgpEuflcdbJIUGIEUIStEM46v sOga9YM+OJb9YZwSHplP5k3AJlDffI6U6CnwzT6TEdCwmdwA0uEDdl3x6s3wD//cPLnO /u1A== X-Gm-Message-State: AOJu0YzSnMZF361OuTymbl29IVwYPTqeMikDFOWrkaNMoMk0WqJr+Idk FHZhzK5QJjojb8TWsSWbXGbMcYknTC3UXyz4Awof/TUd6sQMISSCtXkbMg== X-Google-Smtp-Source: AGHT+IFqlmftUTut1d4OEy1puYmBlxfpET79eFTNHLvEIfrq2HGHmU3J2UMSDGOFmJzh/1IYSpwsdg== X-Received: by 2002:a05:620a:233:b0:79f:1cf:551e with SMTP id af79cd13be357-79f19a51e10mr994387585a.5.1720731678018; Thu, 11 Jul 2024 14:01:18 -0700 (PDT) Original-Received: from smtpclient.apple ([131.183.131.33]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79f1902966csm327036885a.55.2024.07.11.14.01.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jul 2024 14:01:17 -0700 (PDT) In-Reply-To: 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:288748 Archived-At: --Apple-Mail=_81DD6890-84BD-4B48-ACF9-160C3B7CA8C1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jul 6, 2024, at 5:09=E2=80=AFPM, Paul Eggert = wrote: >=20 > On 7/6/24 21:29, JD Smith wrote: >> do we universally avoid unicode in core files? >=20 > Not in comments, but even today it's wise to be cautious about = generating user-visible Unicode characters like "=C2=BD" when there's a = simple ASCII substitute like ".5". Plus, why stop with =C2=BD? Why not = also do =C2=BC and =C2=BE? >=20 > It might be better to have an optional precision argument, defaulting = to 0, specifying the number of digits of precision after the decimal = point. Or something like that. Thanks for the feedback. Attached find an updated patch: - HALF is dropped. - PRECISION can now be specified as a whole-number of digits or a float = <1.0 (e.g. 0.5) - NEWS and doc entries. Users who want =C2=BD can always use precision=3D0.5 and edit the string = after the fact. Another attached file includes commands to produce and display a simple = benchmark, as well as the example output (below). =20 I see about a 10x performance difference between the standard = seconds-to-string and the "bells and whistles" readable version. It's = still <35=C2=B5s per delay for me, so formatting thousands of strings at = once should be no problem. Happy to take performance improvement ideas. Current example: Delay (s) s2s s2s-r s2s-ra s2s-ra1 s2s-rah = s2s-e s2s-ea s2s-ea1 s2s-ea3 s2s-eah 0.000 0s 0 seconds 0s 0s 0s = 0 seconds 0s 0s 0s 0s 0.450 450.00ms 0 seconds 0s 0.4s 0.5s = 0 seconds 0s 0.4s 0.450s 0.5s 1.035 1.03s 1 second 1s 1s 1s = 1 second 1s 1s 1.035s 1s 2.380 2.38s 2 seconds 2s 2.4s 2.5s = 2 seconds 2s 2.4s 2.380s 2.5s 5.475 5.48s 5 seconds 5s 5.5s 5.5s = 5 seconds 5s 5.5s 5.475s 5.5s 12.593 12.59s 13 seconds 13s 12.6s 12.5s = 13 seconds 13s 12.6s 12.593s 12.5s 28.964 28.96s 29 seconds 29s 29s 29s = 29 seconds 29s 29s 28.964s 29s 66.616 66.62s 1 minute 1m 1.1m 1m 1 = minute 7 seconds 1m 7s 1m 6.6s 1m 6.616s 1m 6.5s 153.217 2.55m 3 minutes 3m 2.6m 2.5m 2 = minutes 33 seconds 2m 33s 2m 33.2s 2m 33.217s 2m 33s 352.399 5.87m 6 minutes 6m 5.9m 6m 5 = minutes 52 seconds 5m 52s 5m 52.4s 5m 52.399s 5m 52.5s 810.519 13.51m 14 minutes 14m 13.5m 13.5m 13 = minutes 31 seconds 13m 31s 13m 30.5s 13m 30.519s 13m 30.5s 1864.193 31.07m 31 minutes 31m 31.1m 31m 31 = minutes 4 seconds 31m 4s 31m 4.2s 31m 4.193s 31m 4s 4287.644 71.46m 1 hour 1h 1.2h 1h 1 = hour 11 minutes 1h 11m 1h 11.5m 1h 11.461m 1h 11.5m 9861.581 2.74h 3 hours 3h 2.7h 2.5h 2 = hours 44 minutes 2h 44m 2h 44.4m 2h 44.360m 2h 44.5m 22681.636 6.30h 6 hours 6h 6.3h 6.5h 6 = hours 18 minutes 6h 18m 6h 18m 6h 18.027m 6h 18m 52167.763 14.49h 14 hours 14h 14.5h 14.5h 14 = hours 29 minutes 14h 29m 14h 29.5m 14h 29.463m 14h 29.5m 119985.856 1.39d 1 day 1d 1.4d 1.5d = 1 day 9 hours 1d 9h 1d 9.3h 1d 9.329h 1d 9.5h 275967.469 3.19d 3 days 3d 3.2d 3d = 3 days 5 hours 3d 5h 3d 4.7h 3d 4.658h 3d 4.5h 634725.178 7.35d 1 week 1w 1w 1w = 1 week 1w 1w 0.3d 1w 0.346d 1w 0.5d 1459867.909 16.90d 2 weeks 2w 2.4w 2.5w = 2 weeks 3 days 2w 3d 2w 2.9d 2w 2.897d 2w 3d 3357696.192 38.86d 1 month 1M 1.3M 1.5M = 1 month 1 week 1M 1w 1M 1.2w 1M 1.204w 1M 1w 7722701.241 89.38d 3 months 3M 2.9M 3M 2 = months 4 weeks 2M 4w 2M 4.1w 2M 4.073w 2M 4w 17762212.854 205.58d 7 months 7M 6.8M 7M 6 = months 3 weeks 6M 3w 6M 3.3w 6M 3.280w 6M 3.5w 40853089.565 1.29y 1 year 1Y 1.3Y 1.5Y 1 = year 4 months 1Y 4M 1Y 3.5M 1Y 3.535M 1Y 3.5M 93962105.999 2.98y 3 years 3Y 3Y 3Y 2 = years 12 months 2Y 12M 2Y 11.7M 2Y 11.730M 2Y 11.5M 216112843.798 6.85y 7 years 7Y 6.8Y 7Y 6 = years 10 months 6Y 10M 6Y 10.2M 6Y 10.180M 6Y 10M 497059540.736 15.75y 16 years 16Y 15.8Y 16Y 15 = years 9 months 15Y 9M 15Y 9M 15Y 9.014M 15Y 9M 1143236943.694 36.23y 36 years 36Y 36.2Y 36Y 36 = years 3 months 36Y 3M 36Y 2.7M 36Y 2.733M 36Y 2.5M =EF=BF=BC=EF=BF=BC --Apple-Mail=_81DD6890-84BD-4B48-ACF9-160C3B7CA8C1 Content-Type: multipart/mixed; boundary="Apple-Mail=_D8586D9C-C13F-4E19-A681-AEC92B23B7C7" --Apple-Mail=_D8586D9C-C13F-4E19-A681-AEC92B23B7C7 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Jul 6, 2024, at 5:09=E2=80=AFPM, Paul Eggert = <eggert@cs.ucla.edu> wrote:

On 7/6/24 21:29, JD Smith = wrote:
do we universally avoid unicode in = core files?

Not in comments, but even today it's = wise to be cautious about generating user-visible Unicode characters = like "=C2=BD" when there's a simple ASCII substitute like ".5". Plus, = why stop with =C2=BD? Why not also do =C2=BC and =C2=BE?

It might = be better to have an optional precision argument, defaulting to 0, = specifying the number of digits of precision after the decimal point. Or = something like that.

Thanks = for the feedback.  Attached find an updated = patch:

- HALF is dropped.
- PRECISION = can now be specified as a whole-number of digits or a float <1.0 = (e.g. 0.5)
- NEWS and doc = entries.

Users who want =C2=BD can always use = precision=3D0.5 and edit the string after the = fact.

Another attached file includes commands = to produce and display a simple benchmark, as well as the example output = (below).  

I see about a 10x performance = difference between the standard seconds-to-string and the "bells and = whistles" readable version.  It's still <35=C2=B5s per delay for = me, so formatting thousands of strings at once should be no problem. =  Happy to take performance improvement = ideas.

Current example:

     Delay (s)        s2s =       s2s-r  s2s-ra  s2s-ra1  s2s-rah =                  s2s-e =   s2s-ea    s2s-ea1      s2s-ea3   =  s2s-eah
    =      0.000         0s   0 = seconds      0s       0s     =   0s              0 seconds =       0s         0s     =       0s         = 0s
      =    0.450   450.00ms   0 seconds     =  0s     0.4s     0.5s       =        0 seconds       0s   =     0.4s       0.450s       = 0.5s
      =    1.035      1.03s    1 second =      1s       1s       1s =               1 second     =   1s         1s       1.035s =         1s
         2.380      2.38s =   2 seconds      2s     2.4s     = 2.5s              2 seconds   =     2s       2.4s       2.380s =       2.5s
         5.475      5.48s =   5 seconds      5s     5.5s     = 5.5s              5 seconds   =     5s       5.5s       5.475s =       5.5s
        12.593     12.59s  13 = seconds     13s    12.6s    12.5s   =           13 seconds      13s =      12.6s      12.593s     =  12.5s
    =     28.964     28.96s  29 seconds     = 29s      29s      29s       =       29 seconds      29s     =    29s      28.964s       =  29s
    =     66.616     66.62s    1 minute   =    1m     1.1m       1m     = 1 minute 7 seconds    1m 7s    1m 6.6s   =  1m 6.616s    1m 6.5s
       153.217      2.55m =   3 minutes      3m     2.6m     = 2.5m   2 minutes 33 seconds   2m 33s   2m 33.2s   2m = 33.217s     2m 33s
       352.399      5.87m =   6 minutes      6m     5.9m     =   6m   5 minutes 52 seconds   5m 52s   5m 52.4s =   5m 52.399s   5m 52.5s
       810.519     13.51m  14 = minutes     14m    13.5m    13.5m  13 = minutes 31 seconds  13m 31s  13m 30.5s  13m 30.519s =  13m 30.5s
  =     1864.193     31.07m  31 minutes   =   31m    31.1m      31m   31 minutes = 4 seconds   31m 4s   31m 4.2s   31m 4.193s     = 31m 4s
      = 4287.644     71.46m      1 hour     =  1h     1.2h       1h     =  1 hour 11 minutes   1h 11m   1h 11.5m   1h 11.461m =   1h 11.5m
  =     9861.581      2.74h     3 hours =      3h     2.7h     2.5h   =   2 hours 44 minutes   2h 44m   2h 44.4m   2h = 44.360m   2h 44.5m
     22681.636      6.30h   =   6 hours      6h     6.3h     = 6.5h     6 hours 18 minutes   6h 18m     6h 18m =   6h 18.027m     6h 18m
     52167.763     14.49h =    14 hours     14h    14.5h   =  14.5h    14 hours 29 minutes  14h 29m  14h = 29.5m  14h 29.463m  14h 29.5m
    119985.856      1.39d =       1 day      1d     1.4d =     1.5d          1 day 9 hours =    1d 9h    1d 9.3h    1d 9.329h   =  1d 9.5h
    = 275967.469      3.19d      3 days   =    3d     3.2d       3d     =     3 days 5 hours    3d 5h    3d 4.7h =    3d 4.658h    3d 4.5h
    634725.178      7.35d =      1 week      1w       = 1w       1w             =     1 week       1w    1w 0.3d   =  1w 0.346d    1w 0.5d
   1459867.909     16.90d     2 = weeks      2w     2.4w     2.5w =         2 weeks 3 days    2w 3d   =  2w 2.9d    2w 2.897d      2w = 3d
   3357696.192 =     38.86d     1 month      1M   =   1.3M     1.5M         1 month 1 = week    1M 1w    1M 1.2w    1M 1.204w =      1M 1w
   7722701.241     89.38d    3 = months      3M     2.9M       3M =       2 months 4 weeks    2M 4w    2M = 4.1w    2M 4.073w      2M = 4w
  17762212.854 =    205.58d    7 months      7M   =   6.8M       7M       6 months 3 = weeks    6M 3w    6M 3.3w    6M 3.280w =    6M 3.5w
  = 40853089.565      1.29y      1 year   =    1Y     1.3Y     1.5Y     =    1 year 4 months    1Y 4M    1Y 3.5M =    1Y 3.535M    1Y 3.5M
  93962105.999      2.98y =     3 years      3Y       3Y =       3Y      2 years 12 months   2Y = 12M   2Y 11.7M   2Y 11.730M   2Y = 11.5M
 216112843.798 =      6.85y     7 years      7Y =     6.8Y       7Y      6 years = 10 months   6Y 10M   6Y 10.2M   6Y 10.180M     = 6Y 10M
 497059540.736 =     15.75y    16 years     16Y   =  15.8Y      16Y      15 years 9 = months   15Y 9M     15Y 9M   15Y 9.014M   =   15Y 9M
1143236943.694 =     36.23y    36 years     36Y   =  36.2Y      36Y      36 years 3 = months   36Y 3M   36Y 2.7M   36Y 2.733M   36Y = 2.5M

= --Apple-Mail=_D8586D9C-C13F-4E19-A681-AEC92B23B7C7 Content-Disposition: attachment; filename=s2s_test.el Content-Type: application/octet-stream; x-unix-mode=0644; name="s2s_test.el" Content-Transfer-Encoding: quoted-printable (require=20'cl-lib)=0A=0A(defun=20s2s/example=20()=0A=20=20(interactive)=0A= =20=20(with-temp-buffer-window=20"s2s/example"=20nil=20nil=0A=20=20=20=20= (princ=0A=20=20=20=20=20(concat=0A=20=20=20=20=20=20(format=20"%14s=20= %10s=20=20%10s=20=20%6s=20=20%7s=20=20%7s=20=20%21s=20=20%7s=20=20%9s=20=20= %11s=20=20%9s\n"=0A=09=20=20=20=20=20=20"Delay=20(s)"=20"s2s"=20"s2s-r"=20= "s2s-ra"=20"s2s-ra1"=20"s2s-rah"=20"s2s-e"=20"s2s-ea"=20"s2s-ea1"=0A=09=20= =20=20=20=20=20"s2s-ea3"=20"s2s-eah")=0A=20=20=20=20=20=20(cl-loop=20for=20= s=20=3D=200.0=20then=20(if=20(zerop=20s)=200.45=20(*=20s=202.3))=0A=09=20= =20=20=20=20=20=20while=20(<=20s=20(*=20365.25=2024=203600=2040))=0A=09=20= =20=20=20=20=20=20concat=20(format=20"%14.3f=20%10s=20=20%10s=20=20%6s=20= =20%7s=20=20%7s=20=20%21s=20=20%7s=20=20%9s=20=20%11s=20=20%9s\n"=20s=0A=09= =09=09=20=20=20=20=20=20(seconds-to-string=20s)=0A=09=09=09=20=20=20=20=20= =20(seconds-to-string=20s=20'readable)=0A=09=09=09=20=20=20=20=20=20= (seconds-to-string=20s=20'readable=20'abbrev)=0A=09=09=09=20=20=20=20=20=20= (seconds-to-string=20s=20'readable=20'abbrev=201)=0A=09=09=09=20=20=20=20= =20=20(seconds-to-string=20s=20'readable=20'abbrev=200.5)=0A=09=09=09=20=20= =20=20=20=20(seconds-to-string=20s=20'expanded)=0A=09=09=09=20=20=20=20=20= =20(seconds-to-string=20s=20'expanded=20'abbrev)=0A=09=09=09=20=20=20=20=20= =20(seconds-to-string=20s=20'expanded=20'abbrev=201)=0A=09=09=09=20=20=20= =20=20=20(seconds-to-string=20s=20'expanded=20'abbrev=203)=0A=09=09=09=20= =20=20=20=20=20(seconds-to-string=20s=20'expanded=20'abbrev=200.5)))))))=0A= =0A(defun=20s2s/benchmark=20()=0A=20=20(interactive)=0A=20=20(let*=20= ((ndelays=20100000)=0A=09=20(delays=20(cl-loop=20for=20i=20from=201=20to=20= ndelays=0A=09=09=09=20=20with=20max=20=3D=20(*=20365.25=2024=203600=20= 40)=0A=09=09=09=20=20collect=20(cl-random=20max)))=0A=09=20(bsmpl=20= (benchmark-run=20nil=0A=09=09=20=20(cl-loop=20for=20d=20in=20delays=0A=09= =09=09=20=20=20do=20(seconds-to-string=20d))))=0A=09=20(brdbl=20= (benchmark-run=20nil=0A=09=09=20=20(cl-loop=20for=20d=20in=20delays=0A=09= =09=09=20=20=20do=20(seconds-to-string=20d=20t=20t=200.1)))))=0A=20=20=20= =20(with-temp-buffer-window=20"s2s/benchmarks"=20nil=20nil=0A=20=20=20=20= =20=20(princ=20"seconds-to-string=20benchmarks\n")=0A=20=20=20=20=20=20= (princ=20(format=20"=20=20default=20timing:=20%0.2f=C2=B5s\n\t%S\n"=0A=09= =09=20=20=20=20=20(/=20(car=20bsmpl)=20ndelays=201e-6)=20bsmpl))=0A=20=20= =20=20=20=20(princ=20(format=20"=20readable=20timing:=20= %0.2f=C2=B5s\n\t%S\n\n"=0A=09=09=20=20=20=20=20(/=20(car=20brdbl)=20= ndelays=201e-6)=20brdbl))=0A=20=20=20=20=20=20(princ=20(format=20= "readable/default:=20%0.2f\n"=20(/=20(car=20brdbl)=20(car=20bsmpl)))))))=0A= --Apple-Mail=_D8586D9C-C13F-4E19-A681-AEC92B23B7C7 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii
--Apple-Mail=_D8586D9C-C13F-4E19-A681-AEC92B23B7C7 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=204767735197fba78672e076737a033921637db1a2=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|=2075=20= ++++++++++++++++++++++++++++++++++++--=0A=203=20files=20changed,=2084=20= insertions(+),=204=20deletions(-)=0A=0Adiff=20--git=20= a/doc/lispref/os.texi=20b/doc/lispref/os.texi=0Aindex=20= 3ba3da459bf..1e26c83de6a=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"2=20hours=2044=20= minutes".=0A+=0A=20@node=20Timers=0A=20@section=20Timers=20for=20Delayed=20= Execution=0A=20@cindex=20timers=0Adiff=20--git=20a/etc/NEWS=20b/etc/NEWS=0A= index=20f10f9ae4d65..38ab21288a3=20100644=0A---=20a/etc/NEWS=0A+++=20= b/etc/NEWS=0A@@=20-30,6=20+30,13=20@@=20applies,=20and=20please=20also=20= update=20docstrings=20as=20needed.=0A=20=0C=0A=20*=20Changes=20in=20= Emacs=2031.1=0A=20=0A+**=20Time=20&=20Date=0A+=0A++++=0A+***=20= 'seconds-to-string'=20includes=20new=20arguments=20to=20produce=20= human-readable=0A+delay=20strings=20in=20a=20variety=20of=20formats,=20= for=20example=20"6=20months=203=20weeks"=20or=0A+"5m=2052.5s".=0A+=0A=20=0C= =0A=20*=20Editing=20Changes=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..f80aa2f980d=20100644=0A---=20a/lisp/calendar/time-date.el=0A= +++=20b/lisp/calendar/time-date.el=0A@@=20-409,11=20+409,78=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+=0A=20= ;;;###autoload=0A-(defun=20seconds-to-string=20(delay)=0A-=20=20;;=20= FIXME:=20There's=20a=20similar=20(tho=20fancier)=20function=20in=20= mastodon.el!=0A-=20=20"Convert=20the=20time=20interval=20in=20seconds=20= to=20a=20short=20string."=0A-=20=20(cond=20((>=200=20delay)=20(concat=20= "-"=20(seconds-to-string=20(-=20delay))))=0A+(defun=20seconds-to-string=20= (delay=20&optional=20readable=20abbrev=20precision)=0A+=20=20"Convert=20= time=20interval=20DELAY=20(in=20seconds)=20to=20a=20short=20string.=0A= +By=20default,=20the=20returned=20string=20has=20two=20decimal=20= precision=20in=20the=0A+smallest=20unit=20that=20is=20larger=20than=20= DELAY=20from=20the=20variable=0A+`seconds-to-string'.=20=20If=20READABLE=20= is=20non-nil,=20convert=20DELAY=20into=0A+a=20readable=20string,=20using=20= the=20information=20in=20the=20variable=0A+`seconds-to-string-readable'.=20= =20If=20it=20is=20the=20symbol=20`expanded',=0A+use=20two=20units=20to=20= describe=20DELAY,=20if=20appropriate.=20=20E.g.=20\"1=20hour=0A+32=20= minutes\".=20=20If=20ABBREV=20is=20non-nil,=20abbreviate=20the=20= readable=0A+units.=20=20If=20PRECISION=20is=20a=20whole=20number,=20= round=20the=20value=0A+associated=20with=20the=20smallest=20displayed=20= unit=20to=20that=20many=20digits=0A+after=20the=20decimal.=20=20If=20it=20= a=20non-negative=20float=20less=20than=201.0,=0A+round=20to=20that=20= value."=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.43.0=0A=0A= --Apple-Mail=_D8586D9C-C13F-4E19-A681-AEC92B23B7C7 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii


--Apple-Mail=_D8586D9C-C13F-4E19-A681-AEC92B23B7C7-- --Apple-Mail=_81DD6890-84BD-4B48-ACF9-160C3B7CA8C1--