Date: Thu, 31 May 2001 08:46:30 -0700 (PDT) From: jabley@mfnx.net To: FreeBSD-gnats-submit@freebsd.org Subject: bin/27796: Use of -v flag of date(1) can give non-intuitive results Message-ID: <200105311546.IAA22666@box.mfnx.net>
next in thread | raw e-mail | index | archive | help
>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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200105311546.IAA22666>
