From owner-freebsd-bugs@FreeBSD.ORG Fri Jan 30 18:40:13 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BF98316A4CE for ; Fri, 30 Jan 2004 18:40:13 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7310343D1F for ; Fri, 30 Jan 2004 18:40:11 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i0V2eBFR011706 for ; Fri, 30 Jan 2004 18:40:11 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i0V2eAUY011705; Fri, 30 Jan 2004 18:40:10 -0800 (PST) (envelope-from gnats) Date: Fri, 30 Jan 2004 18:40:10 -0800 (PST) Message-Id: <200401310240.i0V2eAUY011705@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Edwin Groothuis Subject: Re: bin/62134: strange date -v results X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 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, 31 Jan 2004 02:40:13 -0000 The following reply was made to PR bin/62134; it has been noted by GNATS. From: Edwin Groothuis To: Danijel Tasov Cc: FreeBSD-gnats-submit@FreeBSD.org Subject: Re: bin/62134: strange date -v results Date: Sat, 31 Jan 2004 13:30:43 +1100 man date says: Adjust (i.e., take the current date and display the result of the adjustment; not actually set the date) the second, minute, hour, month day, week day, month or year according to val. If val is preceded with a plus or minus sign, the date is adjusted forwards or backwards according to the remaining string, otherwise the relevant part of the date is set. The date can be adjusted as many times as required using these flags. Flags are processed in the order given. [...] When the date is adjusted to a specific value that doesn't actually exist (for example March 26, 1:30 BST 2000 in the Europe/London timezone), the date will be silently adjusted forwards 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. So what you're doing is, on januari 30th or 31st: for i in 1 2 3; do date -v2004y -v${i}m -v17d +%Y-%m-%d; done Loop i=1: step 1. current date is 2004-01-31 step 2. -v2004y: set current year to 2004, date will become 2004-01-31 step 3. -v1m: set current month to 1, date will become 2004-01-31 step 4. -v17d: set current day to 17, date will become 2004-01-17 Loop i=2: step 1. current date is 2004-01-31 step 2. -v2004y: set current year to 2004, date will become 2004-01-31 step 3. -v2m: set current month to 2, date will become 2004-02-31 Unfortunatly this date doesn't exist, so it takes the next best value and date will become 2004-03-01. step 4. -v17d: set current day to 17, date will become 2004-03-17 Loop i=3: step 1. current date is 2004-01-31 step 2. -v2004y: set current year to 2004, date will become 2004-01-31 step 3. -v3m: set current month to 2, date will become 2004-03-31 step 4. -v17d: set current day to 17, date will become 2004-03-17 Same problem will happen when you add the 4th month to the list. So the right syntax would be: for i in 1 2 3; do date -v17d -v${i}m -v2004y +%Y-%m-%d; done -- Edwin Groothuis | Personal website: http://www.mavetju.org edwin@mavetju.org | Weblog: http://weblog.barnet.com.au/edwin/