Bug 201062 - Calendar did not show Father's day on June 22, 2015 using calendar.usholiday
Summary: Calendar did not show Father's day on June 22, 2015 using calendar.usholiday
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.1-STABLE
Hardware: amd64 Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
Depends on:
Reported: 2015-06-22 23:58 UTC by Richard Narron
Modified: 2015-06-22 23:58 UTC (History)
0 users

See Also:

Calendar Father's Day patch (1.47 KB, patch)
2015-06-22 23:58 UTC, Richard Narron
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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)
    d = (idayofweek - dow + 7) % 7 + 1;