From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#43677: 27.1; Calc holidays off-by-one error, incorrect business day calculation Date: Wed, 30 Sep 2020 04:50:25 +0200 Message-ID: <87sgb07zbi.fsf@gnus.org> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7571"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 43677@debbugs.gnu.org To: Aaron Zeng Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 30 04:51:13 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 1kNSD2-0001sW-TT for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Sep 2020 04:51:12 +0200 Original-Received: from localhost ([::1]:56588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNSD1-0004QQ-Ss for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 29 Sep 2020 22:51:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNSCs-0004QK-J0 for bug-gnu-emacs@gnu.org; Tue, 29 Sep 2020 22:51:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46155) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kNSCs-0002Ku-8b for bug-gnu-emacs@gnu.org; Tue, 29 Sep 2020 22:51:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kNSCs-0002o5-5H for bug-gnu-emacs@gnu.org; Tue, 29 Sep 2020 22:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Sep 2020 02:51: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.160143424010761 (code B ref 43677); Wed, 30 Sep 2020 02:51:02 +0000 Original-Received: (at 43677) by debbugs.gnu.org; 30 Sep 2020 02:50:40 +0000 Original-Received: from localhost ([127.0.0.1]:57701 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNSCW-0002nV-0Z for submit@debbugs.gnu.org; Tue, 29 Sep 2020 22:50:40 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:40130) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNSCT-0002nG-UK for 43677@debbugs.gnu.org; Tue, 29 Sep 2020 22:50:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=7xFrb1Z2BHnYIpLexyb5YAxjiJOqIi9Qqy24TtB8COM=; b=mBXm/OFT7dSYmHaijKWVVYum6W v4Gh/9NA81FciclD5uFYPovZ9K/GCQvlhz5OH2Zgpy53qWZtHvz5+C4dNFiH6gtqg+6qV/h/glitm Qm9kPDVMw3ZNHX/FwaKkhR0o+vJiB7nm70A+Bh7+pWy1JWZkd0lEPH3+4OlywnLiLNGE=; Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNSCI-0005Xx-PP; Wed, 30 Sep 2020 04:50:30 +0200 X-Now-Playing: Farben's _Says: Don't Fight Phrases_: "As Long As There's Love Around" In-Reply-To: (Aaron Zeng's message of "Sun, 27 Sep 2020 21:18:50 -0400") 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:189304 Archived-At: Aaron Zeng writes: > I observe the following incorrect behavior starting from `emacs -Q`: > > 1. M-x calc > 2. ' <2020-11-01> RET --- displays "" > 3. 1 t - --- should have subtracted one business day, but it displays > "" instead of "" > > Adding a business day to Saturday gives Tuesday instead of Monday. It > seems like this is would be an off-by-one error. This appears to be > confirmed by setting the Holidays vector in calc (`s e Holidays`) to > be `[fri, sat]` and trying the above procedure again. > > After applying the workaround, instead of seeing Saturday and Tuesday > as the previous and next business days, respectively, I see Friday and > Monday as I would expect. Indeed -- applying the following patch (which numbers Monday as 0 and Sunday as 6) makes the test case work correctly for me. But trying to follow the code makes it unclear... er... what's going on, and there aren't many comments in the Calc code to explain what they were thinking. I wondered whether this might be a US/non-US thing (with a difference in what day starts the week), but I couldn't really find anything in calc talking about that... Does anybody have any insight here? diff --git a/lisp/calc/calc-forms.el b/lisp/calc/calc-forms.el index 5a8f0a38d2..5d3629ea0a 100644 --- a/lisp/calc/calc-forms.el +++ b/lisp/calc/calc-forms.el @@ -1928,8 +1928,8 @@ math-sh-year (defun math-setup-holidays (&optional date) (or (eq (calc-var-value 'var-Holidays) math-holidays-cache-tag) (let ((h (calc-var-value 'var-Holidays)) - (wdnames '( (sun . 0) (mon . 1) (tue . 2) (wed . 3) - (thu . 4) (fri . 5) (sat . 6) )) + (wdnames '( (mon . 0) (tue . 1) (wed . 2) + (thu . 3) (fri . 4) (sat . 5) (sun . 6) )) (days nil) (weekdays nil) (exprs nil) (limit nil) (hours nil)) (or (math-vectorp h) (math-reject-arg h "*Holidays variable must be a vector")) -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no