From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#43759: Emacs Calc date conversion Date: Fri, 2 Oct 2020 19:31:09 +0200 Message-ID: <0BC1BBB7-6524-4DA2-90D7-37807994E388@acm.org> References: <87o8lkwvvj.fsf@gnus.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.17\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_1AE4D75C-4940-4083-9699-C6077DFD5AF7" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19800"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Vincent =?UTF-8?Q?Bela=C3=AFche?= , 43759@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 02 19:32:22 2020 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 1kOOur-00050J-UR for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 02 Oct 2020 19:32:22 +0200 Original-Received: from localhost ([::1]:54642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOOuq-00078I-Uf for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 02 Oct 2020 13:32:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44058) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOOuZ-00076M-Ii for bug-gnu-emacs@gnu.org; Fri, 02 Oct 2020 13:32:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59122) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOOuZ-0002q2-8Z for bug-gnu-emacs@gnu.org; Fri, 02 Oct 2020 13:32:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kOOuZ-00011r-62 for bug-gnu-emacs@gnu.org; Fri, 02 Oct 2020 13:32:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 02 Oct 2020 17:32:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43759 X-GNU-PR-Package: emacs Original-Received: via spool by 43759-submit@debbugs.gnu.org id=B43759.16016598803889 (code B ref 43759); Fri, 02 Oct 2020 17:32:03 +0000 Original-Received: (at 43759) by debbugs.gnu.org; 2 Oct 2020 17:31:20 +0000 Original-Received: from localhost ([127.0.0.1]:42434 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kOOtr-00010f-M0 for submit@debbugs.gnu.org; Fri, 02 Oct 2020 13:31:19 -0400 Original-Received: from mail228c50.megamailservers.eu ([91.136.10.238]:37148 helo=mail36c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kOOtm-00010S-M0 for 43759@debbugs.gnu.org; Fri, 02 Oct 2020 13:31:18 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1601659872; bh=P89XEvq23EOZbPwgUgaA+aY9WeTf48XRpZVsVqkvAaI=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=T7+d0YdtRGPVXvwT+tosxJkxXvI6Pu39/8Tz2Kj6oJPjErKfnnsk2xfN260t2Srmk /YtjnClqxc1olfQesYKDPZzc1VtWyrchmOA5brlE3xNpErDwtg6zQh5nlOv2J0Tm/o 1hnPG8v2fmK1nq+dhIGnv6GhdbRcW2++dcU1F0+I= Feedback-ID: mattiase@acm.or Original-Received: from stanniol.lan (c-304ee655.032-75-73746f71.bbcust.telenor.se [85.230.78.48]) (authenticated bits=0) by mail36c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 092HV9A0019882; Fri, 2 Oct 2020 17:31:11 +0000 In-Reply-To: <87o8lkwvvj.fsf@gnus.org> X-Mailer: Apple Mail (2.3445.104.17) X-CTCH-RefID: str=0001.0A782F23.5F7763E0.0017, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=PeiBeRpd c=1 sm=1 tr=0 a=63Z2wlQ1NB3xHpgKFKE71g==:117 a=63Z2wlQ1NB3xHpgKFKE71g==:17 a=M51BFTxLslgA:10 a=OocQHUDgAAAA:8 a=voEmyLi3Y555m_72J3MA:9 a=_J5qM0MSNCC8cjq0:21 a=92qlKjG8qyaVrUb6:21 a=CjuIK1q_8ugA:10 a=CADzTnd9ZfJ7LcTqauIA:9 a=B2y7HmGcmWMA:10 a=xUZTl98r3Qw_uB5NK3jt:22 X-Origin-Country: SE 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" Xref: news.gmane.io gmane.emacs.bugs:189668 Archived-At: --Apple-Mail=_1AE4D75C-4940-4083-9699-C6077DFD5AF7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 2 okt. 2020 kl. 16.22 skrev Lars Ingebrigtsen : > This is another off-by-one-day bug, though, so perhaps it's related to > the same change from a few years ago that changed day zero? Actually this error is unrelated. It has been there since Calc was added = to the Emacs tree in 2001: the number of days from the Calc epoch to = start of Unix time was incorrectly given as 719164 but the correct = number was 719162 before the change in Calc epoch in 2012, and since = then it should be 719163. The "t U" command was fixed in 2015 (e368697ce36) along with the = documentation. The attached patch fixes the remaining uses of the wrong = constant, in the date parsing and formatting code. Vincent, is this = patch helpful? --Apple-Mail=_1AE4D75C-4940-4083-9699-C6077DFD5AF7 Content-Disposition: attachment; filename=0001-Calc-fix-formatting-and-parsing-Unix-time-bug-43759.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Calc-fix-formatting-and-parsing-Unix-time-bug-43759.patch" Content-Transfer-Encoding: quoted-printable =46rom=20fb718a57123036e40cb8b3b813d734e590a104fa=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Fri,=202=20Oct=202020=2018:50:50=20+0200=0A= Subject:=20[PATCH]=20Calc:=20fix=20formatting=20and=20parsing=20Unix=20= time=20(bug#43759)=0AMIME-Version:=201.0=0AContent-Type:=20text/plain;=20= charset=3DUTF-8=0AContent-Transfer-Encoding:=208bit=0A=0AThe=20number=20= of=20days=20from=20epoch=20to=20Jan=201,=201970=20that=20was=20used=20in=20= parsing=0Aand=20formatting=20Unix=20time=20was=20incorrect.=20=20The=20= previous=20fix=0A(in=20e368697ce36)=20was=20incomplete.=0A=0AReported=20= by=20Vincent=20Bela=C3=AFche.=0A=0A*=20lisp/calc/calc-forms.el=20= (math-unix-epoch):=20New=20constant.=0A(math-format-date-part,=20= math-parse-standard-date,=20calcFunc-unixtime):=0AUse=20math-unix-epoch=20= instead=20of=20a=20constant=20that=20is=20sometimes=20wrong.=0A---=0A=20= lisp/calc/calc-forms.el=20=20=20=20=20=20|=2013=20++++++++----=0A=20= test/lisp/calc/calc-tests.el=20|=2041=20= ++++++++++++++++++++++++++++++++++++=0A=202=20files=20changed,=2050=20= insertions(+),=204=20deletions(-)=0A=0Adiff=20--git=20= a/lisp/calc/calc-forms.el=20b/lisp/calc/calc-forms.el=0Aindex=20= 6d70126c09..a2f6696866=20100644=0A---=20a/lisp/calc/calc-forms.el=0A+++=20= b/lisp/calc/calc-forms.el=0A@@=20-709,6=20+709,10=20@@=20= math-julian-date-beginning-int=0A=20=20=20"The=20beginning=20of=20the=20= Julian=20date=20calendar,=0A=20as=20measured=20in=20the=20integer=20= number=20of=20days=20before=20December=2031,=201=20BC=20(Gregorian).")=0A= =20=0A+(defconst=20math-unix-epoch=20719163=0A+=20=20"The=20beginning=20= of=20Unix=20time:=20days=20from=20December=2031,=201=20BC=20(Gregorian)=0A= +to=20Jan=201,=201970=20AD.")=0A+=0A=20(defun=20math-format-date-part=20= (x)=0A=20=20=20(cond=20((stringp=20x)=0A=20=09=20x)=0A@@=20-730,7=20= +734,8=20@@=20math-format-date-part=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=20=20=20=20=20(math-floor=20= math-fd-date)=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=20=20=20=20=20math-julian-date-beginning-int)))=0A=20= =09((eq=20x=20'U)=0A-=09=20(math-format-number=20(nth=201=20= (math-date-parts=20math-fd-date=20719164))))=0A+=09=20= (math-format-number=20(nth=201=20(math-date-parts=20math-fd-date=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=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= =20math-unix-epoch))))=0A=20=20=20=20=20=20=20=20=20((memq=20x=20'(IYYY=20= Iww=20w))=0A=20=20=20=20=20=20=20=20=20=20(progn=0A=20=20=20=20=20=20=20=20= =20=20=20=20(or=20math-fd-iso-dt=0A@@=20-1173,7=20+1178,7=20@@=20= math-parse-standard-date=0A=20=09=09=20=20=20=20=20=20(setq=20num=20= (math-match-substring=20math-pd-str=200)=0A=20=09=09=09=20=20=20=20= math-pd-str=20(substring=20math-pd-str=20(match-end=200))=0A=20=09=09=09=20= =20=20=20num=20(math-date-to-dt=0A-=09=09=09=09=20(math-add=20719164=0A+=09= =09=09=09=20(math-add=20math-unix-epoch=0A=20=09=09=09=09=09=20=20=20= (math-div=20(math-read-number=20num)=0A=20=09=09=09=09=09=09=20=20=20=20=20= '(float=20864=202))))=0A=20=09=09=09=20=20=20=20hour=20(nth=203=20num)=0A= @@=20-1434,11=20+1439,11=20@@=20calcFunc-julian=0A=20(defun=20= calcFunc-unixtime=20(date=20&optional=20zone)=0A=20=20=20(if=20= (math-realp=20date)=0A=20=20=20=20=20=20=20(progn=0A-=09(setq=20date=20= (math-add=20719163=20(math-div=20date=20'(float=20864=202))))=0A+=09= (setq=20date=20(math-add=20math-unix-epoch=20(math-div=20date=20'(float=20= 864=202))))=0A=20=09(list=20'date=20(math-sub=20date=20(math-div=20= (calcFunc-tzone=20zone=20date)=0A=20=09=09=09=09=09=20=20=20=20=20= '(float=20864=202)))))=0A=20=20=20=20=20(if=20(eq=20(car=20date)=20= 'date)=0A-=09(math-add=20(nth=201=20(math-date-parts=20(nth=201=20date)=20= 719163))=0A+=09(math-add=20(nth=201=20(math-date-parts=20(nth=201=20= date)=20math-unix-epoch))=0A=20=09=09=20=20(calcFunc-tzone=20zone=20= date))=0A=20=20=20=20=20=20=20(math-reject-arg=20date=20'datep))))=0A=20=0A= diff=20--git=20a/test/lisp/calc/calc-tests.el=20= b/test/lisp/calc/calc-tests.el=0Aindex=204dded007f7..6eb0788052=20100644=0A= ---=20a/test/lisp/calc/calc-tests.el=0A+++=20= b/test/lisp/calc/calc-tests.el=0A@@=20-534,6=20+534,47=20@@=20= calc-business-days=0A=20=20=20=20=20=20=20)=0A=20=20=20))=0A=20=0A= +(ert-deftest=20calc-unix-date=20()=0A+=20=20(cl-flet=20((m=20(s)=20= (math-parse-date=20s)))=0A+=20=20=20=20;;=20calcFunc-unixtime=20(command=20= "t=20U")=20converts=20a=20date=20value=20to=20Unix=20time,=0A+=20=20=20=20= ;;=20and=20a=20number=20to=20a=20date.=0A+=20=20=20=20(should=20(equal=20= (m=20"1970-01-01")=20'(date=20719163)))=0A+=20=20=20=20(should=20(equal=20= (calcFunc-unixtime=20(m=20"1970-01-01")=200)=200))=0A+=20=20=20=20= (should=20(equal=20(calc-tests--calc-to-number=20(cadr=20= (calcFunc-unixtime=200=200)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20(cadr=20(m=20"1970-01-01"))))=0A+=20=20=20=20(should=20= (equal=20(calcFunc-unixtime=20(m=20"2020-09-07")=200)=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20(*=20(-=20(cadr=20(m=20= "2020-09-07"))=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(cadr=20(m=20"1970-01-01")))=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=2086400)))=0A+=20=20=20=20= (should=20(equal=20(calcFunc-unixtime=20(m=20"1991-01-09=2006:00")=200)=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20663400800))=0A= +=20=20=20=20(should=20(equal=20(calc-tests--calc-to-number=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(cadr=20= (calcFunc-unixtime=20663400800=200)))=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20726841.25))=0A+=0A+=20=20=20=20(let*=20= ((d-1970-01-01=20(m=20"1970-01-01"))=0A+=20=20=20=20=20=20=20=20=20=20=20= (d-2020-09-07=20(m=20"2020-09-07"))=0A+=20=20=20=20=20=20=20=20=20=20=20= (d-1991-01-09-0600=20(m=20"1991-01-09=2006:00"))=0A+=20=20=20=20=20=20=20= =20=20=20=20(calc-date-format=20'(U)))=0A+=20=20=20=20=20=20;;=20Test=20= parsing=20Unix=20time.=0A+=20=20=20=20=20=20(should=20(equal=20= (calc-tests--calc-to-number=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20(cadr=20(math-parse-date=20"0")))=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20719163))=0A+=20=20=20=20= =20=20(should=20(equal=20(calc-tests--calc-to-number=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(cadr=20(math-parse-date=20= "469324800")))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(+=20719163=20(/=20469324800=2086400))))=0A+=20=20=20=20=20=20= (should=20(equal=20(calc-tests--calc-to-number=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(cadr=20(math-parse-date=20= "663400800")))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20726841.25))=0A+=0A+=20=20=20=20=20=20;;=20Test=20formatting=20Unix=20= time.=0A+=20=20=20=20=20=20(should=20(equal=20(math-format-date=20= d-1970-01-01)=20"0"))=0A+=20=20=20=20=20=20(should=20(equal=20= (math-format-date=20d-2020-09-07)=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(number-to-string=20(*=20(-=20(cadr=20= d-2020-09-07)=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=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20(cadr=20d-1970-01-01))=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=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=2086400))))=0A+=20=20=20=20=20=20(should=20(equal=20= (math-format-date=20d-1991-01-09-0600)=20"663400800")))))=0A+=0A=20= (provide=20'calc-tests)=0A=20;;;=20calc-tests.el=20ends=20here=0A=20=0A= --=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_1AE4D75C-4940-4083-9699-C6077DFD5AF7--