From owner-freebsd-bugs@FreeBSD.ORG Sat Jun 2 13:00:11 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id D0C4F16A421 for ; Sat, 2 Jun 2007 13:00:11 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id AB52013C45A for ; Sat, 2 Jun 2007 13:00:11 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l52D0Bn0095156 for ; Sat, 2 Jun 2007 13:00:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l52D0BUw095155; Sat, 2 Jun 2007 13:00:11 GMT (envelope-from gnats) Resent-Date: Sat, 2 Jun 2007 13:00:11 GMT Resent-Message-Id: <200706021300.l52D0BUw095155@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Edwin Groothuis Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0F03A16A468 for ; Sat, 2 Jun 2007 12:59:34 +0000 (UTC) (envelope-from edwin@mavetju.org) Received: from mail4out.barnet.com.au (mail4.barnet.com.au [202.83.178.125]) by mx1.freebsd.org (Postfix) with ESMTP id 962B313C44B for ; Sat, 2 Jun 2007 12:59:33 +0000 (UTC) (envelope-from edwin@mavetju.org) Received: by mail4out.barnet.com.au (Postfix, from userid 1001) id 4DCE137DA20; Sat, 2 Jun 2007 22:59:32 +1000 (EST) Received: from mail4auth.barnet.com.au (mail4.barnet.com.au [202.83.178.125]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mail4.barnet.com.au (Postfix) with ESMTP id 051C3422114 for ; Sat, 2 Jun 2007 22:59:32 +1000 (EST) Received: from k7.mavetju (k7.mavetju.org [10.251.1.18]) by mail4auth.barnet.com.au (Postfix) with ESMTP id A447137DA0F for ; Sat, 2 Jun 2007 22:59:31 +1000 (EST) Received: by k7.mavetju (Postfix, from userid 1001) id 78E7A2E; Sat, 2 Jun 2007 22:59:31 +1000 (EST) Message-Id: <20070602125931.78E7A2E@k7.mavetju> Date: Sat, 2 Jun 2007 22:59:31 +1000 (EST) From: Edwin Groothuis To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/113250: [patch] fix calendar -A and -B options X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Edwin Groothuis List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jun 2007 13:00:12 -0000 >Number: 113250 >Category: bin >Synopsis: [patch] fix calendar -A and -B options >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Jun 02 13:00:10 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Edwin Groothuis >Release: FreeBSD 6.2-RELEASE-p4 i386 >Organization: - >Environment: System: FreeBSD k7.mavetju 6.2-RELEASE-p4 FreeBSD 6.2-RELEASE-p4 #0: Thu Apr 26 17:55:55 UTC 2007 root@i386-builder.daemonology.net:/usr/obj/usr/src/sys/SMP i386 >Description: calendar has the following two options: -A num Print lines from today and the next num days (forward, future). -B num Print lines from today and the previous num days (backward, past). Currently, while using the attached calibration file, calendar says: [/usr/src/usr.bin/calendar] root@k7>calendar -B 3 -f c.calibrate -t 04.01.2006 Jan 1 jan 1 Jan 2 jan 2 Jan 3 jan 3 Jan 4 jan 4 Jan 5 jan 5 That is one day too much [/usr/src/usr.bin/calendar] root@k7>calendar -B 3 -f c.calibrate -t 01.01.2006 Jan 1 jan 1 Jan 2 jan 2 Jan 3 jan 3 That is not three days before 01.01.2006 [/usr/src/usr.bin/calendar] root@k7>calendar -A 3 -f c.calibrate -t 27.12.2006 Dec 27 dec 27 Dec 28 dec 28 Dec 29 dec 29 Dec 30 dec 30 Dec 31 dec 31 That is one day too much [/usr/src/usr.bin/calendar] root@k7>calendar -A 3 -f c.calibrate -t 31.12.2006 Jan 1 jan 1 Jan 2 jan 2 Jan 3 jan 3 Jan 4 jan 4 Dec 31 dec 31 That is in the wrong order >How-To-Repeat: Use this calendar file: calendar.calibration file: 01/01 jan 1 01/02 jan 2 01/03 jan 3 01/04 jan 4 01/05 jan 5 01/06 jan 6 01/07 jan 7 01/08 jan 8 01/09 jan 9 12/22 dec 22 12/23 dec 23 12/24 dec 24 12/25 dec 25 12/26 dec 26 12/27 dec 27 12/28 dec 28 12/29 dec 29 12/30 dec 30 12/31 dec 31 Fix: Instead of doing the matches of before, after, offset etc in one function, split it out properly. First do checks if the standard dates have to be given, then check if the -A or -B option is given. --- day.c.orig Sat Jun 2 14:48:00 2007 +++ day.c Sat Jun 2 22:46:57 2007 @@ -381,17 +381,45 @@ #ifdef DEBUG fprintf(stderr, "day2: day %d(%d-%d) yday %d\n", *dayp, day, cumdays[month], tp->tm_yday); #endif - /* if today or today + offset days */ + + /* when only today and tomorrow (or today and the next three days if + it is friday) is needed */ + if (f_dayBefore == 0 && + f_dayAfter == 0 ) { + /* no year rollover */ + if (day >= tp->tm_yday && + day <= tp->tm_yday + offset) + return (1); + /* year rollover */ + if (tp->tm_yday + offset >= yrdays) { + int end = tp->tm_yday + offset - yrdays; + if (day <= end) + return (1); + } + + return (0); + } + + /* When days before or days after is specified */ + /* no year rollover */ if (day >= tp->tm_yday - f_dayBefore && - day <= tp->tm_yday + offset + f_dayAfter) + day <= tp->tm_yday + f_dayAfter) return (1); - /* if number of days left in this year + days to event in next year */ - if (yrdays - tp->tm_yday + day <= offset + f_dayAfter || - /* a year backward, eg. 6 Jan and 10 days before -> 27. Dec */ - tp->tm_yday + day - f_dayBefore < 0 - ) - return (1); + /* next year */ + if (tp->tm_yday + f_dayAfter >= yrdays) { + int end = tp->tm_yday + f_dayAfter - yrdays; + if (day <= end) + return (1); + } + + /* previous year */ + if (tp->tm_yday - f_dayBefore < 0) { + int before = yrdays + (tp->tm_yday - f_dayBefore ); + if (day >= before) + return (1); + } + return (0); } >Fix: >Release-Note: >Audit-Trail: >Unformatted: