Date: Fri, 30 Jan 2004 18:40:10 -0800 (PST) From: Edwin Groothuis <edwin@mavetju.org> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/62134: strange date -v results Message-ID: <200401310240.i0V2eAUY011705@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/62134; it has been noted by GNATS. From: Edwin Groothuis <edwin@mavetju.org> To: Danijel Tasov <dt@vosat.de> 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/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200401310240.i0V2eAUY011705>