Bug 201062

Summary: Calendar did not show Father's day on June 22, 2015 using calendar.usholiday
Product: Base System Reporter: Richard Narron <comet.berkeley>
Component: binAssignee: Oleksandr Tymoshenko <gonzo>
Status: Closed FIXED    
Severity: Affects Some People CC: carlj, gonzo, katsubsd
Priority: --- Flags: gonzo: mfc-stable12+
gonzo: mfc-stable11+
Version: 10.1-STABLE   
Hardware: amd64   
OS: Any   
Attachments:
Description Flags
Calendar Father's Day patch none

Description Richard Narron 2015-06-22 23:58:48 UTC
Created attachment 158000 [details]
Calendar Father's Day patch

The calendar.usholiday file contains 42 lines of which 2 are relevant to June 21, 2015:
06/SunThird     Father's Day (3rd Sunday of June)
06/21*  Summer Solstice

My .calendar/calendar file includes this one line:
#include <calendar.usholiday>

And when calendar runs it should show two lines out, one for Father's Day and one for the Solstice:

$calendar -t21.6.2015
Jun 21* Summer Solstice

I patched the code (calendar.c and parsedata.c) and the problem seems to be fixed.

$calendar -t21.6.2015
Jun 21* Summer Solstice
Jun 21* Father's Day (3rd Sunday of June)

To debug this it was helpful to set the debug_remember flag in
the dates.c code.  This flag is a global integer and can be set from calendar.c when the -d option (debug) is set.

In parsedata.c, the calculation of the first day of the recurring weekdays is wrong as it is trying to calculate a day of the month but will always return an integer in the range 0-6.  0 is always wrong...

It was:
    d = (idayofweek - dow + 8) % 7;

But should be:
    d = (idayofweek - dow + 7) % 7 + 1;  

Additionally the variable dow can be -1 and when it is the code should probably stop (continue) so a better patch is this:

    if (dow < 0)
        continue;
    d = (idayofweek - dow + 7) % 7 + 1;
Comment 1 commit-hook freebsd_committer freebsd_triage 2020-04-03 01:26:26 UTC
A commit references this bug:

Author: gonzo
Date: Fri Apr  3 01:17:44 UTC 2020
New revision: 359585
URL: https://svnweb.freebsd.org/changeset/base/359585

Log:
  Fix calculation of the recurring weekdays

  Both the result of the first_dayofweek_of_year and the target
  weekday are zero-based (0 fo sunday) while the target month-day
  or year-day is 1-based. Adjust logic accordingly.

  Also add testcase for this PR to the kyua test suite

  PR:		201062
  Submitted by:	Richard Narron <comet.berkeley@gmail.com>
  MFC after:	1 week

Changes:
  head/usr.bin/calendar/parsedata.c
  head/usr.bin/calendar/tests/calendar.calibrate
  head/usr.bin/calendar/tests/regress.s5.out
  head/usr.bin/calendar/tests/regress.sh
Comment 2 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2020-04-03 02:02:41 UTC
*** Bug 240427 has been marked as a duplicate of this bug. ***
Comment 3 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2020-04-03 02:03:19 UTC
*** Bug 234663 has been marked as a duplicate of this bug. ***
Comment 4 commit-hook freebsd_committer freebsd_triage 2020-04-10 22:18:28 UTC
A commit references this bug:

Author: gonzo
Date: Fri Apr 10 22:18:14 UTC 2020
New revision: 359782
URL: https://svnweb.freebsd.org/changeset/base/359782

Log:
  MFC r359585, r359587

  r359585:
  Fix calculation of the recurring weekdays

  Both the result of the first_dayofweek_of_year and the target
  weekday are zero-based (0 fo sunday) while the target month-day
  or year-day is 1-based. Adjust logic accordingly.

  Also add testcase for this PR to the kyua test suite

  PR:		201062
  Submitted by:	Richard Narron <comet.berkeley@gmail.com>

  r359587:
  Remove hardcoded US Election Day from calendar.usholiday

  calendar(1) syntax is not capable of representing the rules for the
  US Election Day. The hardcoded date was set in r15066 in 1996 and
  hasn't changed since then.

  PR:		173389
  Reported by:	Steve Ames <steve@energistic.com>

Changes:
_U  stable/12/
  stable/12/usr.bin/calendar/calendars/calendar.usholiday
  stable/12/usr.bin/calendar/parsedata.c
  stable/12/usr.bin/calendar/tests/calendar.calibrate
  stable/12/usr.bin/calendar/tests/regress.s5.out
  stable/12/usr.bin/calendar/tests/regress.sh
Comment 5 commit-hook freebsd_committer freebsd_triage 2020-04-10 22:19:30 UTC
A commit references this bug:

Author: gonzo
Date: Fri Apr 10 22:18:31 UTC 2020
New revision: 359783
URL: https://svnweb.freebsd.org/changeset/base/359783

Log:
  MFC r359585, r359587

  r359585:
  Fix calculation of the recurring weekdays

  Both the result of the first_dayofweek_of_year and the target
  weekday are zero-based (0 fo sunday) while the target month-day
  or year-day is 1-based. Adjust logic accordingly.

  Also add testcase for this PR to the kyua test suite

  PR:		201062
  Submitted by:	Richard Narron <comet.berkeley@gmail.com>

  r359587:
  Remove hardcoded US Election Day from calendar.usholiday

  calendar(1) syntax is not capable of representing the rules for the
  US Election Day. The hardcoded date was set in r15066 in 1996 and
  hasn't changed since then.

  PR:		173389
  Reported by:	Steve Ames <steve@energistic.com>

Changes:
_U  stable/11/
  stable/11/usr.bin/calendar/calendars/calendar.usholiday
  stable/11/usr.bin/calendar/parsedata.c
  stable/11/usr.bin/calendar/tests/calendar.calibrate
  stable/11/usr.bin/calendar/tests/regress.s5.out
  stable/11/usr.bin/calendar/tests/regress.sh