Thus said Solene Rapenne on Wed, 09 Jan 2019 15:01:13 +0100:

> On OpenBSD-current amd64 last snapshot, when using calendar -B flag, I
> get a date  which is due in 3  days when I want to show  events in the
> past 33 days. Using an other range  of days doesn't work, it has to be
> 33. Past events are correctly shown though.

The problem is caused by the way  that offset is derived for the special
handling of Friday. If the day in the date is a Friday, offset is set to
3 so that events  happening on the weekend are printed.  In the case you
presented, you set -t 20190109 which does  not land on a Friday, but the
way the code  currently works it takes  your -B 33 and sets  the date to
20181207 which *is* a  Friday. Now offset is set to 3  and it makes your
-B 33 extend the 20181207 all the  way to 20190112 which matches your 12
January calendar entry.

It looks like  currently if -A is used the  Friday handling is disabled,
so the following patch also disables it when -B is used.

Alternatively, the  question arises, should Friday  handling be disabled
when -A or -B are used?

Question for the list: given that this is my first time posting on bugs@
I'm not  sure if patches are  expected here or on  tech@ when addressing
bugs. Guidance appreciated if necessary.

Index: calendar.c
===================================================================
RCS file: /home/cvs/src/usr.bin/calendar/calendar.c,v
retrieving revision 1.35
diff -u -p -r1.35 calendar.c
--- calendar.c  7 Dec 2015 18:46:35 -0000       1.35
+++ calendar.c  24 Jan 2019 15:05:35 -0000
@@ -60,7 +60,7 @@ int bodun_always = 0;
 
 int f_dayAfter = 0; /* days after current date */
 int f_dayBefore = 0; /* days before current date */
-int f_SetdayAfter = 0; /* calendar invoked with -A */
+int f_Setday = 0; /* calendar invoked with -A or -B */
 
 struct specialev spev[NUMEV];
 
@@ -101,13 +101,14 @@ main(int argc, char *argv[])
                        f_dayAfter = strtonum(optarg, 0, INT_MAX, &errstr);
                        if (errstr)
                                errx(1, "-A %s: %s", optarg, errstr);
-                       f_SetdayAfter = 1;
+                       f_Setday = 1;
                        break;
 
                case 'B': /* days before current date */
                        f_dayBefore = strtonum(optarg, 0, INT_MAX, &errstr);
                        if (errstr)
                                errx(1, "-B %s: %s", optarg, errstr);
+                       f_Setday = 1;
                        break;
 
                case 'w':
Index: calendar.h
===================================================================
RCS file: /home/cvs/src/usr.bin/calendar/calendar.h,v
retrieving revision 1.15
diff -u -p -r1.15 calendar.h
--- calendar.h  7 Dec 2015 18:46:35 -0000       1.15
+++ calendar.h  24 Jan 2019 15:05:35 -0000
@@ -103,7 +103,7 @@ void         setnnames(void);
 
 extern int f_dayAfter; /* days after current date */
 extern int f_dayBefore;        /* days before current date */
-extern int f_SetdayAfter; /* calendar invoked with -A */
+extern int f_Setday; /* calendar invoked with -A or -B */
 
 /* Special events; see also setnnames() in day.c */
 /* '=' is not a valid character in a special event name */
Index: day.c
===================================================================
RCS file: /home/cvs/src/usr.bin/calendar/day.c,v
retrieving revision 1.34
diff -u -p -r1.34 day.c
--- day.c       14 Sep 2016 15:09:46 -0000      1.34
+++ day.c       24 Jan 2019 15:05:35 -0000
@@ -166,7 +166,7 @@ settime(time_t *now)
                cumdays = daytab[0];
        /* Friday displays Monday's events */
        offset = tp->tm_wday == 5 ? 3 : 1;
-       if (f_SetdayAfter)
+       if (f_Setday)
                offset = 0;     /* Except not when range is set explicitly */
        header[5].iov_base = dayname;
 
Andy
-- 
TAI64 timestamp: 400000005c49d789


Reply via email to