From owner-freebsd-bugs Thu May 31 8:50: 8 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 46FF337B43C for ; Thu, 31 May 2001 08:50:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f4VFo2f10311; Thu, 31 May 2001 08:50:02 -0700 (PDT) (envelope-from gnats) Received: from box.mfnx.net (box.mfnx.net [64.124.216.37]) by hub.freebsd.org (Postfix) with ESMTP id B752637B422 for ; Thu, 31 May 2001 08:46:30 -0700 (PDT) (envelope-from jabley@mfnx.net) Received: (from jabley@localhost) by box.mfnx.net (8.9.3/8.9.1) id IAA22666; Thu, 31 May 2001 08:46:30 -0700 (PDT) env-from (jabley@mfnx.net) Message-Id: <200105311546.IAA22666@box.mfnx.net> Date: Thu, 31 May 2001 08:46:30 -0700 (PDT) From: jabley@mfnx.net Reply-To: jabley@mfnx.net To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/27796: Use of -v flag of date(1) can give non-intuitive results Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 27796 >Category: bin >Synopsis: Use of -v flag of date(1) can give non-intuitive results >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: Thu May 31 08:50:01 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Joe Abley >Release: FreeBSD 3.4-RELEASE i386 >Organization: Metromedia Fiber Network >Environment: Tested on FreeBSD 3.4-RELEASE and also 4.3-STABLE #1 >Description: jabley@goose[132]$ date Thu May 31 11:44:23 EDT 2001 jabley@goose[133]$ date -v+1m Sun Jul 1 11:44:25 EDT 2001 jabley@goose[134]$ date -v+1m +%m jabley@goose[136]$ date -v+1m +%m 07 Intuitively, I would expect "date -v+1m +%m" to mean "tell me the number of next month", and return 06 instead of 07. Looking at the source to date(1), it looks as though -v+1m just adds 1 to the tm_mon element of the struct tm (see src/bin/date/vary.c). The problem then is that the resulting date is 31 June 2001, and since June only has 30 days, the month gets wrapped. As the manual page says: When the date is adjusted to a specific value that doesn't actu- ally exist (for example March 26, 1:30 BST 2000 in the Europe/London timezone), the date will be silently adjusted for- wards in units of one hour until it reaches a valid time. When the date is adjusted to a specific value that occurs twice (for example October 29, 1:30 2000), the resulting timezone will be set so that the date matches the earlier of the two times. It doesn't say so explicitly, but I suspect similar logic is being applied to days that don't exist within a month. >How-To-Repeat: jabley@goose[132]$ date Thu May 31 11:44:23 EDT 2001 jabley@goose[133]$ date -v+1m Sun Jul 1 11:44:25 EDT 2001 jabley@goose[134]$ date -v+1m +%m jabley@goose[136]$ date -v+1m +%m 07 Run on any day N of month M where month (M+1) has less than N days. >Fix: None suggested -- I'm not sure if my semantic understanding of the -v flag is accurate. >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message