From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#36822: 26.2; Calc: calc-julian produces incorrect result Date: Tue, 30 Jul 2019 17:51:00 +0200 Message-ID: References: Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_83D2ABDC-7861-41B2-90CD-BF34147AF6A6" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="224652"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 36822@debbugs.gnu.org To: michel@schi.nz Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 30 17:52:09 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hsUQ5-000wJL-2H for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 Jul 2019 17:52:09 +0200 Original-Received: from localhost ([::1]:34114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsUQ4-0001Ce-1B for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 Jul 2019 11:52:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47706) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsUPz-0001CE-6O for bug-gnu-emacs@gnu.org; Tue, 30 Jul 2019 11:52:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsUPy-0000kw-9A for bug-gnu-emacs@gnu.org; Tue, 30 Jul 2019 11:52:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42223) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsUPx-0000kf-RQ for bug-gnu-emacs@gnu.org; Tue, 30 Jul 2019 11:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hsUPx-00016h-Nl for bug-gnu-emacs@gnu.org; Tue, 30 Jul 2019 11:52:01 -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: Tue, 30 Jul 2019 15:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36822 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 36822-submit@debbugs.gnu.org id=B36822.15645018694186 (code B ref 36822); Tue, 30 Jul 2019 15:52:01 +0000 Original-Received: (at 36822) by debbugs.gnu.org; 30 Jul 2019 15:51:09 +0000 Original-Received: from localhost ([127.0.0.1]:51044 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsUP7-00015N-0g for submit@debbugs.gnu.org; Tue, 30 Jul 2019 11:51:09 -0400 Original-Received: from mail172c50.megamailservers.eu ([91.136.10.182]:56340 helo=mail33c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsUP3-000155-Gr; Tue, 30 Jul 2019 11:51:06 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1564501863; bh=msUC34yIDDq5zUmzmDTCrk9RUQ1X5VZJ/9xF4bY+NJY=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=DXLbvCDzcKuNDkqBbzzeqMOLJo0jRSP9uykvjc4TEx4rOhxOFD+F2cdFlh8zmmMvB Yypvl8BVwNf8F4KettKGczY4Q/ddPnG3fj06k+HsvpqnPqmBBbZLyVMZg/oH+Wullh tbaZvR/6gq9mo6ZPvgxflymjaL7lfOOHq+mTJJMM= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] ([188.150.171.71]) (authenticated bits=0) by mail33c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x6UFp0qg015947; Tue, 30 Jul 2019 15:51:02 +0000 In-Reply-To: X-Mailer: Apple Mail (2.3445.104.11) X-CTCH-RefID: str=0001.0A0B0206.5D406767.0038, 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=GYc5YzfL c=1 sm=1 tr=0 a=SF+I6pRkHZhrawxbOkkvaA==:117 a=SF+I6pRkHZhrawxbOkkvaA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=8IraQf0k_r41KMDgSLoA:9 a=CjuIK1q_8ugA:10 a=JZnqBebJGJOuWfoRXq0A:9 a=B2y7HmGcmWMA:10 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:164117 Archived-At: --Apple-Mail=_83D2ABDC-7861-41B2-90CD-BF34147AF6A6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii tags 36822 patch quit > It looks like there are multiple flaws involved. This was indeed the case. Attached is a patch that attempts to fix those = that I found (I didn't dig very deeply). As I'm no calendar expert, I would greatly value an independent review = of the patch. --Apple-Mail=_83D2ABDC-7861-41B2-90CD-BF34147AF6A6 Content-Disposition: attachment; filename=0001-Fix-various-Calc-date-conversions-bug-36822.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Fix-various-Calc-date-conversions-bug-36822.patch" Content-Transfer-Encoding: quoted-printable =46rom=200facfe8988f7d0614d8cce124a8a7cabaf7450ed=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Tue,=2030=20Jul=202019=2017:33:19=20+0200=0A= Subject:=20[PATCH]=20Fix=20various=20Calc=20date=20conversions=20= (bug#36822)=0A=0A*=20lisp/calc/calc-forms.el=20= (math-absolute-from-gregorian-dt):=0ARewrite=20in=20a=20way=20that=20I=20= understand,=20and=20that=20actually=20seems=20to=20work.=0A= (math-absolute-from-julian-dt):=20Use=20Julian,=20not=20Gregorian,=20= leap=20year=0Arules=20for=20counting=20days=20within=20a=20year.=0A= (math-julian-date-beginning,=20math-julian-date-beginning-int):=0AChange=20= constants=20to=20be=20consistent=20with=20their=20doc=20strings=20and=20= the=20code:=0Ause=20Rata=20Die=20epoch=20at=20Dec=2031,=201=20BC=20= Gregorian=20proleptic,=20not=20Julian.=0A*=20doc/misc/calc.texi=20(Date=20= Forms):=20Correct=20difference=20between=20Julian=0ADay=20and=20Rata=20= Die.=0A*=20test/lisp/calc/calc-tests.el=20(calc-test-calendar):=20New=20= test.=0A---=0A=20doc/misc/calc.texi=20=20=20=20=20=20=20=20=20=20=20|=20=20= 4=20++--=0A=20lisp/calc/calc-forms.el=20=20=20=20=20=20|=2038=20= ++++++++++++------------------------=0A=20test/lisp/calc/calc-tests.el=20= |=2021=20++++++++++++++++++++=0A=203=20files=20changed,=2035=20= insertions(+),=2028=20deletions(-)=0A=0Adiff=20--git=20= a/doc/misc/calc.texi=20b/doc/misc/calc.texi=0Aindex=20= 75bbae58b2..c13ba8b940=20100644=0A---=20a/doc/misc/calc.texi=0A+++=20= b/doc/misc/calc.texi=0A@@=20-11055,9=20+11055,9=20@@=20Date=20Forms=0A=20= is=20the=20numbers=20of=20days=20since=2012:00=20noon=20(GMT)=20on=20= November=2024,=204714=20BC=0A=20in=20the=20Gregorian=20calendar=20(i.e.,=20= January=201,=204713=20BC=20in=20the=20Julian=0A=20calendar).=20=20In=20= Calc's=20scheme=20(in=20GMT)=20the=20Julian=20day=20origin=20is=0A= -@mathit{-1721422.5},=20because=20Calc=20starts=20at=20midnight=20= instead=20of=20noon.=0A+@mathit{-1721424.5},=20because=20Calc=20starts=20= at=20midnight=20instead=20of=20noon.=0A=20Thus=20to=20convert=20a=20Calc=20= date=20code=20obtained=20by=20unpacking=20a=0A-date=20form=20into=20a=20= Julian=20day=20number,=20simply=20add=201721422.5=20after=0A+date=20form=20= into=20a=20Julian=20day=20number,=20simply=20add=201721424.5=20after=0A=20= compensating=20for=20the=20time=20zone=20difference.=20=20The=20built-in=20= @kbd{t=20J}=0A=20command=20performs=20this=20conversion=20for=20you.=0A=20= =0Adiff=20--git=20a/lisp/calc/calc-forms.el=20b/lisp/calc/calc-forms.el=0A= index=20eb1a8248cd..71127ed779=20100644=0A---=20= a/lisp/calc/calc-forms.el=0A+++=20b/lisp/calc/calc-forms.el=0A@@=20= -585,29=20+585,15=20@@=20math-absolute-from-gregorian-dt=0A=20=20=20= "Return=20the=20DATE=20of=20the=20day=20given=20by=20the=20Gregorian=20= day=20YEAR=20MONTH=20DAY.=0A=20Recall=20that=20DATE=20is=20the=20number=20= of=20days=20since=20December=2031,=20-1=0A=20in=20the=20Gregorian=20= calendar."=0A-=20=20(if=20(eq=20year=200)=20(setq=20year=20-1))=0A-=20=20= (let=20((yearm1=20(math-sub=20year=201)))=0A-=20=20=20=20(math-sub=0A-=20= =20=20=20=20;;=20Add=20the=20number=20of=20days=20of=20the=20year=20and=20= the=20numbers=20of=20days=0A-=20=20=20=20=20;;=20in=20the=20previous=20= years=20(leap=20year=20days=20to=20be=20added=20separately)=0A-=20=20=20=20= =20(math-add=20(math-day-in-year=20year=20month=20day)=0A-=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20(math-add=20(math-mul=20365=20yearm1)=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= ;;=20Add=20the=20number=20of=20Julian=20leap=20years=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(if=20= (math-posp=20year)=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(math-quotient=20yearm1=204)=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= (math-sub=20365=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(math-quotient=20= (math-sub=203=20year)=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=204)))))=0A-=20=20=20=20=20;;=20Subtract=20= the=20number=20of=20Julian=20leap=20years=20which=20are=20not=0A-=20=20=20= =20=20;;=20Gregorian=20leap=20years.=20=20In=20C=3D4N+r=20centuries,=20= there=20will=0A-=20=20=20=20=20;;=20be=203N+r=20of=20these=20days.=20=20= The=20following=20will=20compute=0A-=20=20=20=20=20;;=203N+r.=0A-=20=20=20= =20=20(let*=20((correction=20(math-mul=20(math-quotient=20yearm1=20100)=20= 3))=0A-=20=20=20=20=20=20=20=20=20=20=20=20(res=20(math-idivmod=20= correction=204)))=0A-=20=20=20=20=20=20=20(math-add=20(if=20(=3D=20(cdr=20= res)=200)=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =200=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=201)=0A-=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(car=20res))))))=0A+=20=20= (when=20(zerop=20year)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20;=20Year=20-1=20precedes=20year=201.=0A+=20=20=20=20(setq=20= year=20-1))=0A+=20=20(let*=20((y=20(if=20(>=20year=200)=20year=20(+=20= year=201)))=20=20;=20Astronomical=20year=20(with=200).=0A+=20=20=20=20=20= =20=20=20=20(y1=20(-=20y=201)))=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20;=20Previous=20year.=0A+=20=20=20=20(+=20= (*=20y1=20365)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= ;=20Days=20up=20to=20the=20previous=20year...=0A+=20=20=20=20=20=20=20= (floor=20y1=204)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20;=20= ...=20including=20leap=20days.=0A+=20=20=20=20=20=20=20(-=20(floor=20y1=20= 100))=0A+=20=20=20=20=20=20=20(floor=20y1=20400)=0A+=20=20=20=20=20=20=20= (math-day-in-year=20year=20month=20day))))=0A=20=0A=20(defun=20= math-absolute-from-julian-dt=20(year=20month=20day)=0A=20=20=20"Return=20= the=20DATE=20of=20the=20day=20given=20by=20the=20Julian=20day=20YEAR=20= MONTH=20DAY.=0A@@=20-618,7=20+604,7=20@@=20math-absolute-from-julian-dt=0A= =20=20=20=20=20(math-sub=0A=20=20=20=20=20=20;;=20Add=20the=20number=20= of=20days=20of=20the=20year=20and=20the=20numbers=20of=20days=0A=20=20=20= =20=20=20;;=20in=20the=20previous=20years=20(leap=20year=20days=20to=20= be=20added=20separately)=0A-=20=20=20=20=20(math-add=20(math-day-in-year=20= year=20month=20day)=0A+=20=20=20=20=20(math-add=20(math-day-in-year=20= year=20month=20day=20t)=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (math-add=20(math-mul=20365=20yearm1)=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;;=20Add=20the=20number=20= of=20Julian=20leap=20years=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(if=20(math-posp=20year)=0A@@=20-712,11=20= +698,11=20@@=20math-format-date=0A=20=09=20=20=20=20=20=20=20(setcdr=20= math-fd-dt=20nil))=0A=20=09=20=20fmt))))=0A=20=0A-(defconst=20= math-julian-date-beginning=20'(float=2017214225=20-1)=0A+(defconst=20= math-julian-date-beginning=20'(float=2017214245=20-1)=0A=20=20=20"The=20= beginning=20of=20the=20Julian=20date=20calendar,=0A=20as=20measured=20in=20= the=20number=20of=20days=20before=20December=2031,=201=20BC=20= (Gregorian).")=0A=20=0A-(defconst=20math-julian-date-beginning-int=20= 1721423=0A+(defconst=20math-julian-date-beginning-int=201721425=0A=20=20=20= "The=20beginning=20of=20the=20Julian=20date=20calendar,=0A=20as=20= measured=20in=20the=20integer=20number=20of=20days=20before=20December=20= 31,=201=20BC=20(Gregorian).")=0A=20=0Adiff=20--git=20= a/test/lisp/calc/calc-tests.el=20b/test/lisp/calc/calc-tests.el=0Aindex=20= 77d939eb40..e1ee20b5d2=20100644=0A---=20a/test/lisp/calc/calc-tests.el=0A= +++=20b/test/lisp/calc/calc-tests.el=0A@@=20-193,6=20+193,27=20@@=20= calc-tests-simple=0A=20=20=20=20=20(let=20((calc-number-radix=2036))=0A=20= =20=20=20=20=20=20(should=20(equal=20(math-format-number=2012345678901)=20= "36#5,O6A,QT1")))))=0A=20=0A+(ert-deftest=20calc-test-calendar=20()=0A+=20= =20"Test=20calendar=20conversions=20(bug#36822)."=0A+=20=20(should=20= (equal=20(calcFunc-julian=20(math-parse-date=20"2019-07-27"))=20= 2458692))=0A+=20=20(should=20(equal=20(math-parse-date=20"2019-07-27")=20= '(date=20737267)))=0A+=20=20(should=20(equal=20(calcFunc-julian=20'(date=20= 0))=201721425))=0A+=20=20(should=20(equal=20(math-date-to-gregorian-dt=20= 1)=20'(1=201=201)))=0A+=20=20(should=20(equal=20= (math-date-to-gregorian-dt=200)=20'(-1=2012=2031)))=0A+=20=20(should=20= (equal=20(math-date-to-gregorian-dt=20-1721425)=20'(-4714=2011=2024)))=0A= +=20=20(should=20(equal=20(math-absolute-from-gregorian-dt=202019=207=20= 27)=20737267))=0A+=20=20(should=20(equal=20= (math-absolute-from-gregorian-dt=201=201=201)=201))=0A+=20=20(should=20= (equal=20(math-absolute-from-gregorian-dt=20-1=2012=2031)=200))=0A+=20=20= (should=20(equal=20(math-absolute-from-gregorian-dt=20-99=2012=2031)=20= -35795))=0A+=20=20(should=20(equal=20(math-absolute-from-gregorian-dt=20= -4714=2011=2024)=20-1721425))=0A+=20=20(should=20(equal=20= (calcFunc-julian=20'(date=20-1721425))=200))=0A+=20=20(should=20(equal=20= (math-date-to-julian-dt=201)=20'(1=201=203)))=0A+=20=20(should=20(equal=20= (math-date-to-julian-dt=20-1721425)=20'(-4713=201=201)))=0A+=20=20= (should=20(equal=20(math-absolute-from-julian-dt=202019=201=201)=20= 737073))=0A+=20=20(should=20(equal=20(math-absolute-from-julian-dt=201=20= 1=203)=201))=0A+=20=20(should=20(equal=20(math-absolute-from-julian-dt=20= -101=201=201)=20-36892))=0A+=20=20(should=20(equal=20= (math-absolute-from-julian-dt=20-101=203=201)=20-36832))=0A+=20=20= (should=20(equal=20(math-absolute-from-julian-dt=20-4713=201=201)=20= -1721425)))=0A=20=0A=20(provide=20'calc-tests)=0A=20;;;=20calc-tests.el=20= ends=20here=0A--=20=0A2.20.1=20(Apple=20Git-117)=0A=0A= --Apple-Mail=_83D2ABDC-7861-41B2-90CD-BF34147AF6A6--