unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Aaron Zeng <zeng.aaron.l@gmail.com>
Cc: 43677@debbugs.gnu.org
Subject: bug#43677: 27.1; Calc holidays off-by-one error, incorrect business day calculation
Date: Wed, 30 Sep 2020 04:50:25 +0200	[thread overview]
Message-ID: <87sgb07zbi.fsf@gnus.org> (raw)
In-Reply-To: <CAFTimbVtuL9s7dOXZC=k43jkeEKnjvZ7kFOrFFBhdXb23z-ZrQ@mail.gmail.com> (Aaron Zeng's message of "Sun, 27 Sep 2020 21:18:50 -0400")

Aaron Zeng <zeng.aaron.l@gmail.com> writes:

> I observe the following incorrect behavior starting from `emacs -Q`:
>
> 1. M-x calc
> 2. ' <2020-11-01> RET --- displays "<Sun Nov 1, 2020>"
> 3. 1 t - --- should have subtracted one business day, but it displays
> "<Sat Oct 31, 2020>" instead of "<Fri Oct 30, 2020>"
>
> 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





  reply	other threads:[~2020-09-30  2:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-28  1:18 bug#43677: 27.1; Calc holidays off-by-one error, incorrect business day calculation Aaron Zeng
2020-09-30  2:50 ` Lars Ingebrigtsen [this message]
2020-09-30  8:55   ` Robert Pluim
2020-09-30  9:42 ` Mattias Engdegård
2020-09-30 13:40   ` Lars Ingebrigtsen
2020-09-30 15:52     ` Glenn Morris
2020-09-30 16:22       ` Lars Ingebrigtsen
2020-09-30 16:31         ` Andreas Schwab
2020-09-30 16:12     ` Mattias Engdegård
2020-09-30 16:23       ` Lars Ingebrigtsen
2020-10-01 10:19       ` Mattias Engdegård
2020-10-01 22:47         ` Aaron Zeng
2020-10-02 10:00           ` Mattias Engdegård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sgb07zbi.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=43677@debbugs.gnu.org \
    --cc=zeng.aaron.l@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).