From owner-svn-src-head@freebsd.org Fri Apr 3 01:26:01 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D749826EC1F; Fri, 3 Apr 2020 01:26:01 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48tj1j1XnXz4R0Q; Fri, 3 Apr 2020 01:26:01 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 99FC42368A; Fri, 3 Apr 2020 01:17:44 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0331HitL036411; Fri, 3 Apr 2020 01:17:44 GMT (envelope-from gonzo@FreeBSD.org) Received: (from gonzo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0331Hh1T036408; Fri, 3 Apr 2020 01:17:43 GMT (envelope-from gonzo@FreeBSD.org) Message-Id: <202004030117.0331Hh1T036408@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gonzo set sender to gonzo@FreeBSD.org using -f From: Oleksandr Tymoshenko Date: Fri, 3 Apr 2020 01:17:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r359585 - in head/usr.bin/calendar: . tests X-SVN-Group: head X-SVN-Commit-Author: gonzo X-SVN-Commit-Paths: in head/usr.bin/calendar: . tests X-SVN-Commit-Revision: 359585 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Apr 2020 01:26:02 -0000 Author: gonzo Date: Fri Apr 3 01:17:43 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 MFC after: 1 week Added: head/usr.bin/calendar/tests/regress.s5.out (contents, props changed) Modified: head/usr.bin/calendar/parsedata.c head/usr.bin/calendar/tests/calendar.calibrate head/usr.bin/calendar/tests/regress.sh Modified: head/usr.bin/calendar/parsedata.c ============================================================================== --- head/usr.bin/calendar/parsedata.c Fri Apr 3 00:38:12 2020 (r359584) +++ head/usr.bin/calendar/parsedata.c Fri Apr 3 01:17:43 2020 (r359585) @@ -578,7 +578,9 @@ parsedaymonth(char *date, int *yearp, int *monthp, int /* 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 (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 /* 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, Modified: head/usr.bin/calendar/tests/calendar.calibrate ============================================================================== --- head/usr.bin/calendar/tests/calendar.calibrate Fri Apr 3 00:38:12 2020 (r359584) +++ head/usr.bin/calendar/tests/calendar.calibrate Fri Apr 3 01:17:43 2020 (r359585) @@ -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 Added: head/usr.bin/calendar/tests/regress.s5.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/calendar/tests/regress.s5.out Fri Apr 3 01:17:43 2020 (r359585) @@ -0,0 +1,3 @@ +Jun 21* sunthird +Jun 21 jun 21 +Jun 22 jun 22 Modified: head/usr.bin/calendar/tests/regress.sh ============================================================================== --- head/usr.bin/calendar/tests/regress.sh Fri Apr 3 00:38:12 2020 (r359584) +++ head/usr.bin/calendar/tests/regress.sh Fri Apr 3 01:17:43 2020 (r359585) @@ -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')