diff --git a/usr.bin/calendar/parsedata.c b/usr.bin/calendar/parsedata.c index 32f0cb8f6f6a..becc1ca7bfdf 100644 --- a/usr.bin/calendar/parsedata.c +++ b/usr.bin/calendar/parsedata.c @@ -578,7 +578,9 @@ parsedaymonth(char *date, int *yearp, int *monthp, int *dayp, int *flags, /* Every dayofweek of the year */ if (lflags == (F_DAYOFWEEK | F_VARIABLE)) { dow = first_dayofweek_of_year(year); - d = (idayofweek - dow + 8) % 7; + if (dow < 0) + continue; + d = (idayofweek - dow + 7) % 7 + 1; while (d <= 366) { if (remember_yd(year, d, &rm, &rd)) remember(&remindex, @@ -616,7 +618,9 @@ parsedaymonth(char *date, int *yearp, int *monthp, int *dayp, int *flags, (F_MONTH | F_DAYOFWEEK | F_MODIFIERINDEX | F_VARIABLE)) { offset = indextooffset(modifierindex); dow = first_dayofweek_of_month(year, imonth); - d = (idayofweek - dow + 8) % 7; + if (dow < 0) + continue; + d = (idayofweek - dow + 7) % 7 + 1; if (offset > 0) { while (d <= yearinfo->monthdays[imonth]) { @@ -650,7 +654,9 @@ parsedaymonth(char *date, int *yearp, int *monthp, int *dayp, int *flags, /* Every dayofweek of the month */ if (lflags == (F_DAYOFWEEK | F_MONTH | F_VARIABLE)) { dow = first_dayofweek_of_month(year, imonth); - d = (idayofweek - dow + 8) % 7; + if (dow < 0) + continue; + d = (idayofweek - dow + 7) % 7 + 1; while (d <= yearinfo->monthdays[imonth]) { if (remember_ymd(year, imonth, d)) remember(&remindex, diff --git a/usr.bin/calendar/tests/calendar.calibrate b/usr.bin/calendar/tests/calendar.calibrate index 28e7e4a42268..559218abb251 100644 --- a/usr.bin/calendar/tests/calendar.calibrate +++ b/usr.bin/calendar/tests/calendar.calibrate @@ -188,6 +188,7 @@ LANG=C 06/28 jun 28 06/29 jun 29 06/30 jun 30 +06/SunThird sunthird 07/01 jul 1 07/02 jul 2 07/03 jul 3 diff --git a/usr.bin/calendar/tests/regress.s5.out b/usr.bin/calendar/tests/regress.s5.out new file mode 100644 index 000000000000..8ce6a0cab40a --- /dev/null +++ b/usr.bin/calendar/tests/regress.s5.out @@ -0,0 +1,3 @@ +Jun 21* sunthird +Jun 21 jun 21 +Jun 22 jun 22 diff --git a/usr.bin/calendar/tests/regress.sh b/usr.bin/calendar/tests/regress.sh index 248123ac5dac..9d958f369bc1 100644 --- a/usr.bin/calendar/tests/regress.sh +++ b/usr.bin/calendar/tests/regress.sh @@ -7,12 +7,13 @@ CALENDAR="${CALENDAR_BIN} ${CALENDAR_FILE}" REGRESSION_START($1) -echo 1..28 +echo 1..29 REGRESSION_TEST(`s1',`$CALENDAR -t 29.12.2006') REGRESSION_TEST(`s2',`$CALENDAR -t 30.12.2006') REGRESSION_TEST(`s3',`$CALENDAR -t 31.12.2006') REGRESSION_TEST(`s4',`$CALENDAR -t 01.01.2007') +REGRESSION_TEST(`s5',`$CALENDAR -t 21.06.2015') REGRESSION_TEST(`a1',`$CALENDAR -A 3 -t 28.12.2006') REGRESSION_TEST(`a2',`$CALENDAR -A 3 -t 29.12.2006')