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#43677: 27.1; Calc holidays off-by-one error, incorrect business day calculation Date: Thu, 1 Oct 2020 12:19:47 +0200 Message-ID: References: <0FA74B6A-DD93-41D7-91C4-ED4EB881E2DD@acm.org> <87blhn757u.fsf@gnus.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.17\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_3D5C6B01-2761-4684-AAFB-B58845C724EF" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11166"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Aaron Zeng , 43677@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 01 12:20:12 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 1kNvh6-0002mD-0n for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Oct 2020 12:20:12 +0200 Original-Received: from localhost ([::1]:47884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNvh5-00060w-31 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Oct 2020 06:20:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNvgw-00060n-Tl for bug-gnu-emacs@gnu.org; Thu, 01 Oct 2020 06:20:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kNvgw-0008Cz-KM for bug-gnu-emacs@gnu.org; Thu, 01 Oct 2020 06:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kNvgw-0002H3-Gf for bug-gnu-emacs@gnu.org; Thu, 01 Oct 2020 06:20:02 -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: Thu, 01 Oct 2020 10:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43677 X-GNU-PR-Package: emacs Original-Received: via spool by 43677-submit@debbugs.gnu.org id=B43677.16015476008729 (code B ref 43677); Thu, 01 Oct 2020 10:20:02 +0000 Original-Received: (at 43677) by debbugs.gnu.org; 1 Oct 2020 10:20:00 +0000 Original-Received: from localhost ([127.0.0.1]:34184 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNvgu-0002Gh-BE for submit@debbugs.gnu.org; Thu, 01 Oct 2020 06:20:00 -0400 Original-Received: from mail1452c50.megamailservers.eu ([91.136.14.52]:49338 helo=mail266c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNvgr-0002GQ-5h for 43677@debbugs.gnu.org; Thu, 01 Oct 2020 06:19:59 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1601547590; bh=3Moud1xFjXh2F6rqKPDsFr3fXDoYG6uSFvR7rRgEnL4=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=JmbuqEVOualgOQA3p+QXfY3JMmxkmsmx6IuuMXUd6NIIUhhhf/urCn/2FOyxs5h0Q LJhCYSx2ACjgzXoWiKawhSex1TFfg7X1GZ3K/rVFJdJVst/04ZLKh6TBj/1Xwzi6dj YQZDkCeLNofgXAMlQRP1jfxAqLbO6FMSneRDinTM= 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 mail266c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 091AJmWZ018946; Thu, 1 Oct 2020 10:19:49 +0000 In-Reply-To: X-Mailer: Apple Mail (2.3445.104.17) X-CTCH-RefID: str=0001.0A782F1A.5F75AD46.0067, 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=A5MSwJeG c=1 sm=1 tr=0 a=63Z2wlQ1NB3xHpgKFKE71g==:117 a=63Z2wlQ1NB3xHpgKFKE71g==:17 a=M51BFTxLslgA:10 a=3BP4FDxae5tsqjpcx-YA:9 a=CjuIK1q_8ugA:10 a=wfNsStHubUTYslm3ZvQA:9 a=B2y7HmGcmWMA:10 a=tclcd6dtLQvEqt9_mmAA:9 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:189482 Archived-At: --Apple-Mail=_3D5C6B01-2761-4684-AAFB-B58845C724EF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Aaron, does this patch solve your problem? It turned out that the ability to select arbitrary holiday weekdays = never really worked correctly; the patch attempts to do something about = that as well. The business days code also doesn't work at all very well for BC dates, = which of course limits its applicability somewhat but perhaps not = critically so. Please tell me if that is something you need fixed. --Apple-Mail=_3D5C6B01-2761-4684-AAFB-B58845C724EF Content-Disposition: attachment; filename=0001-Calc-fix-business-days-calculation-bug43677.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Calc-fix-business-days-calculation-bug43677.patch" Content-Transfer-Encoding: quoted-printable =46rom=20802089648160a91876f471c17a400b84b465ce5a=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Wed,=2030=20Sep=202020=2023:57:27=20+0200=0A= Subject:=20[PATCH]=20Calc:=20fix=20business=20days=20calculation=20= (bug43677)=0A=0AThe=20calculation=20of=20business=20days=20was=20broken=20= in=202012=20(probably=0A310e60d9454fe2=20or=20thereabouts)=20when=20the=20= date=20representation=20changed=0Aepoch=20so=20that=20Jan=201,=201=20AD=20= became=20day=20number=201=20instead=20of=200.=20=20Repair=0Athis,=20= along=20with=20an=20unrelated=20bug=20that=20prevented=20arbitrary=20= holiday=0Aweekdays=20from=20working.=0A=0A*=20lisp/calc/calc-forms.el=20= (math-to-business-day)=0A(math-from-business-day):=20Correct=20= calculation=20of=20weekdays=20using=20Calc's=0Acurrent=20(Rata=20Die)=20= chronology.=20=20Modify=20loop=20condition=20to=20cope=20with=20odd=0A= sets=20of=20holiday=20weekdays.=0A*=20test/lisp/calc/calc-tests.el=20= (calc-business-days):=20New=20test.=0A---=0A=20lisp/calc/calc-forms.el=20= =20=20=20=20=20|=2013=20+++---=0A=20test/lisp/calc/calc-tests.el=20|=20= 76=20++++++++++++++++++++++++++++++++++++=0A=202=20files=20changed,=2083=20= insertions(+),=206=20deletions(-)=0A=0Adiff=20--git=20= a/lisp/calc/calc-forms.el=20b/lisp/calc/calc-forms.el=0Aindex=20= 5a8f0a38d2..6d70126c09=20100644=0A---=20a/lisp/calc/calc-forms.el=0A+++=20= b/lisp/calc/calc-forms.el=0A@@=20-1870,8=20+1870,8=20@@=20= math-to-business-day=0A=20=20=20=20=20=20=20(and=20days=20(=3D=20day=20= (car=20days))=0A=20=09=20=20=20(setq=20holiday=20t)))=0A=20=20=20=20=20= (let*=20((weekdays=20(nth=203=20math-holidays-cache))=0A-=09=20=20=20= (weeks=20(1-=20(/=20(+=20day=206)=207)))=0A-=09=20=20=20(wkday=20(-=20= day=201=20(*=20weeks=207))))=0A+=20=20=20=20=20=20=20=20=20=20=20(weeks=20= (/=20day=207))=0A+=20=20=20=20=20=20=20=20=20=20=20(wkday=20(mod=20day=20= 7)))=20=20=20=20=20=20=20=20=20;=20Day=20of=20week:=200=3DSunday,=20= 6=3DSaturday=0A=20=20=20=20=20=20=20(setq=20delta=20(+=20delta=20(*=20= weeks=20(length=20weekdays))))=0A=20=20=20=20=20=20=20(while=20(and=20= weekdays=20(<=20(car=20weekdays)=20wkday))=0A=20=09(setq=20weekdays=20= (cdr=20weekdays)=0A@@=20-1905,14=20+1905,15=20@@=20= math-from-business-day=0A=20=09(setq=20delta=20(1+=20delta)))=0A=20=20=20= =20=20=20=20(setq=20day=20(+=20day=20delta)))=0A=20=20=20=20=20(let*=20= ((weekdays=20(nth=203=20math-holidays-cache))=0A-=09=20=20=20(bweek=20(-=20= 7=20(length=20weekdays)))=0A-=09=20=20=20(weeks=20(1-=20(/=20(+=20day=20= (1-=20bweek))=20bweek)))=0A-=09=20=20=20(wkday=20(-=20day=201=20(*=20= weeks=20bweek)))=0A+=20=20=20=20=20=20=20=20=20=20=20(bweek=20(-=207=20= (length=20weekdays)))=20=20;=20Business=20days=20in=20a=20week,=201..7.=0A= +=20=20=20=20=20=20=20=20=20=20=20(weeks=20(/=20day=20bweek))=20=20=20=20= =20=20=20=20=20=20=20=20;=20Whole=20weeks.=0A+=20=20=20=20=20=20=20=20=20= =20=20(wkday=20(mod=20day=20bweek))=20=20=20=20=20=20;=20Business=20day=20= in=20last=20week,=200..bweek-1=0A=20=09=20=20=20(w=200))=0A=20=20=20=20=20= =20=20(setq=20day=20(+=20day=20(*=20weeks=20(length=20weekdays))))=0A+=20= =20=20=20=20=20;;=20Add=20business=20days=20in=20the=20last=20week;=20= `w'=20is=20weekday,=200..6.=0A=20=20=20=20=20=20=20(while=20(if=20(memq=20= w=20weekdays)=0A=20=09=09=20(setq=20day=20(1+=20day))=0A-=09=20=20=20=20=20= =20=20(>=20(setq=20wkday=20(1-=20wkday))=200))=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(>=3D=20(setq=20wkday=20(1-=20wkday))=200))=0A=20=09= (setq=20w=20(1+=20w)))=0A=20=20=20=20=20=20=20(let=20((hours=20(nth=207=20= math-holidays-cache)))=0A=20=09(if=20hours=0Adiff=20--git=20= a/test/lisp/calc/calc-tests.el=20b/test/lisp/calc/calc-tests.el=0Aindex=20= dce82b6f53..4dded007f7=20100644=0A---=20a/test/lisp/calc/calc-tests.el=0A= +++=20b/test/lisp/calc/calc-tests.el=0A@@=20-458,6=20+458,82=20@@=20= calc-choose=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (calcFunc-choose=20'(frac=20-15=202)=203))=0A=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20(calc-tests--choose=20-7.5=203))))=0A=20=0A= +(ert-deftest=20calc-business-days=20()=0A+=20=20(cl-flet=20((m=20(s)=20= (math-parse-date=20s))=0A+=20=20=20=20=20=20=20=20=20=20=20=20(b+=20(a=20= b)=20(calcFunc-badd=20a=20b))=0A+=20=20=20=20=20=20=20=20=20=20=20=20(b-=20= (a=20b)=20(calcFunc-bsub=20a=20b)))=0A+=20=20=20=20;;=20Sanity=20check.=0A= +=20=20=20=20(should=20(equal=20(m=20"2020-09-07")=20'(date=20737675)))=0A= +=0A+=20=20=20=20;;=20Test=20with=20standard=20business=20days=20= (Mon-Fri):=0A+=20=20=20=20(should=20(equal=20(b+=20(m=20"2020-09-07")=20= 1)=20(m=20"2020-09-08")))=20;=20Mon->Tue=0A+=20=20=20=20(should=20(equal=20= (b+=20(m=20"2020-09-08")=201)=20(m=20"2020-09-09")))=20;=20Tue->Wed=0A+=20= =20=20=20(should=20(equal=20(b+=20(m=20"2020-09-09")=201)=20(m=20= "2020-09-10")))=20;=20Wed->Thu=0A+=20=20=20=20(should=20(equal=20(b+=20= (m=20"2020-09-10")=201)=20(m=20"2020-09-11")))=20;=20Thu->Fri=0A+=20=20=20= =20(should=20(equal=20(b+=20(m=20"2020-09-11")=201)=20(m=20= "2020-09-14")))=20;=20Fri->Mon=0A+=0A+=20=20=20=20(should=20(equal=20(b+=20= (m=20"2020-09-07")=204)=20(m=20"2020-09-11")))=20;=20Mon->Fri=0A+=20=20=20= =20(should=20(equal=20(b+=20(m=20"2020-09-07")=206)=20(m=20= "2020-09-15")))=20;=20Mon->Tue=0A+=0A+=20=20=20=20(should=20(equal=20(b+=20= (m=20"2020-09-12")=201)=20(m=20"2020-09-14")))=20;=20Sat->Mon=0A+=20=20=20= =20(should=20(equal=20(b+=20(m=20"2020-09-13")=201)=20(m=20= "2020-09-14")))=20;=20Sun->Mon=0A+=0A+=20=20=20=20(should=20(equal=20(b-=20= (m=20"2020-09-11")=201)=20(m=20"2020-09-10")))=20;=20Fri->Thu=0A+=20=20=20= =20(should=20(equal=20(b-=20(m=20"2020-09-10")=201)=20(m=20= "2020-09-09")))=20;=20Thu->Wed=0A+=20=20=20=20(should=20(equal=20(b-=20= (m=20"2020-09-09")=201)=20(m=20"2020-09-08")))=20;=20Wed->Tue=0A+=20=20=20= =20(should=20(equal=20(b-=20(m=20"2020-09-08")=201)=20(m=20= "2020-09-07")))=20;=20Tue->Mon=0A+=20=20=20=20(should=20(equal=20(b-=20= (m=20"2020-09-07")=201)=20(m=20"2020-09-04")))=20;=20Mon->Fri=0A+=0A+=20=20= =20=20(should=20(equal=20(b-=20(m=20"2020-09-11")=204)=20(m=20= "2020-09-07")))=20;=20Fri->Mon=0A+=20=20=20=20(should=20(equal=20(b-=20= (m=20"2020-09-15")=206)=20(m=20"2020-09-07")))=20;=20Tue->Mon=0A+=0A+=20=20= =20=20(should=20(equal=20(b-=20(m=20"2020-09-12")=201)=20(m=20= "2020-09-11")))=20;=20Sat->Fri=0A+=20=20=20=20(should=20(equal=20(b-=20= (m=20"2020-09-13")=201)=20(m=20"2020-09-11")))=20;=20Sun->Fri=0A+=0A+=20=20= =20=20;;=20Stepping=20fractional=20days=0A+=20=20=20=20(should=20(equal=20= (b+=20(m=20"2020-09-08=2021:00")=20'(frac=201=202))=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20(m=20"2020-09-09=2009:00")))=0A+=20= =20=20=20(should=20(equal=20(b+=20(m=20"2020-09-11=2021:00")=20'(frac=20= 1=202))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(m=20= "2020-09-14=2009:00")))=0A+=20=20=20=20(should=20(equal=20(b-=20(m=20= "2020-09-08=2021:00")=20'(frac=201=202))=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(m=20"2020-09-08=2009:00")))=0A+=20=20=20=20= (should=20(equal=20(b-=20(m=20"2020-09-14=2006:00")=20'(frac=201=202))=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(m=20= "2020-09-11=2018:00")))=0A+=0A+=20=20=20=20;;=20Test=20with=20a=20couple=20= of=20extra=20days=20off:=0A+=20=20=20=20(let=20((var-Holidays=20(list=20= 'vec=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'(var=20sat=20var-sat)=20'(var=20sun=20var-sun)=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(m=20"2020-09-09")=20(m=20"2020-09-11"))))=0A+=0A+=20=20= =20=20=20=20(should=20(equal=20(b+=20(m=20"2020-09-07")=201)=20(m=20= "2020-09-08")))=20;=20Mon->Tue=0A+=20=20=20=20=20=20(should=20(equal=20= (b+=20(m=20"2020-09-08")=201)=20(m=20"2020-09-10")))=20;=20Tue->Thu=0A+=20= =20=20=20=20=20(should=20(equal=20(b+=20(m=20"2020-09-10")=201)=20(m=20= "2020-09-14")))=20;=20Thu->Mon=0A+=20=20=20=20=20=20(should=20(equal=20= (b+=20(m=20"2020-09-14")=201)=20(m=20"2020-09-15")))=20;=20Mon->Tue=0A+=20= =20=20=20=20=20(should=20(equal=20(b+=20(m=20"2020-09-15")=201)=20(m=20= "2020-09-16")))=20;=20Tue->Wed=0A+=0A+=20=20=20=20=20=20(should=20(equal=20= (b-=20(m=20"2020-09-16")=201)=20(m=20"2020-09-15")))=20;=20Wed->Tue=0A+=20= =20=20=20=20=20(should=20(equal=20(b-=20(m=20"2020-09-15")=201)=20(m=20= "2020-09-14")))=20;=20Tue->Mon=0A+=20=20=20=20=20=20(should=20(equal=20= (b-=20(m=20"2020-09-14")=201)=20(m=20"2020-09-10")))=20;=20Mon->Thu=0A+=20= =20=20=20=20=20(should=20(equal=20(b-=20(m=20"2020-09-10")=201)=20(m=20= "2020-09-08")))=20;=20Thu->Tue=0A+=20=20=20=20=20=20(should=20(equal=20= (b-=20(m=20"2020-09-08")=201)=20(m=20"2020-09-07")))=20;=20Tue->Mon=0A+=20= =20=20=20=20=20)=0A+=0A+=20=20=20=20;;=20Test=20with=20odd=20= non-business=20weekdays=20(Tue,=20Wed,=20Sat):=0A+=20=20=20=20(let=20= ((var-Holidays=20'(vec=20(var=20tue=20var-tue)=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(var=20= wed=20var-wed)=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(var=20sat=20var-sat))))=0A+=20=20=20=20= =20=20(should=20(equal=20(b+=20(m=20"2020-09-07")=201)=20(m=20= "2020-09-10")))=20;=20Mon->Thu=0A+=20=20=20=20=20=20(should=20(equal=20= (b+=20(m=20"2020-09-10")=201)=20(m=20"2020-09-11")))=20;=20Thu->Fri=0A+=20= =20=20=20=20=20(should=20(equal=20(b+=20(m=20"2020-09-11")=201)=20(m=20= "2020-09-13")))=20;=20Fri->Sun=0A+=20=20=20=20=20=20(should=20(equal=20= (b+=20(m=20"2020-09-13")=201)=20(m=20"2020-09-14")))=20;=20Sun->Mon=0A+=0A= +=20=20=20=20=20=20(should=20(equal=20(b-=20(m=20"2020-09-14")=201)=20(m=20= "2020-09-13")))=20;=20Mon->Sun=0A+=20=20=20=20=20=20(should=20(equal=20= (b-=20(m=20"2020-09-13")=201)=20(m=20"2020-09-11")))=20;=20Sun->Fri=0A+=20= =20=20=20=20=20(should=20(equal=20(b-=20(m=20"2020-09-11")=201)=20(m=20= "2020-09-10")))=20;=20Fri->Thu=0A+=20=20=20=20=20=20(should=20(equal=20= (b-=20(m=20"2020-09-10")=201)=20(m=20"2020-09-07")))=20;=20Thu->Mon=0A+=20= =20=20=20=20=20)=0A+=20=20))=0A+=0A=20(provide=20'calc-tests)=0A=20;;;=20= calc-tests.el=20ends=20here=0A=20=0A--=20=0A2.21.1=20(Apple=20Git-122.3)=0A= =0A= --Apple-Mail=_3D5C6B01-2761-4684-AAFB-B58845C724EF Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_3D5C6B01-2761-4684-AAFB-B58845C724EF--