[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: r1.100 of getdate.y changed 'ago' behavior
From: |
Edgar Toernig |
Subject: |
Re: r1.100 of getdate.y changed 'ago' behavior |
Date: |
Wed, 26 Apr 2006 03:29:05 +0200 |
Paul Eggert wrote:
>
> Edgar Toernig <address@hidden> writes:
>
> > Here's a patch.
>
> More important, that patch doesn't fix the bug that prompted the
> code being the way that it is now. Please see the thread rooted
> here:
>
> http://lists.gnu.org/archive/html/bug-coreutils/2005-07/msg00178.html
[ tomorrow/yesterday 1 hour ago ]
Hmm... I wasn't aware of that problem. I just tried to fix the
'1 hour 30 minutes ago' problem.
> People have mentioned shell scripts that depend on the old
> (contrary-to-documentation) behavior. Can you please give some
> specific examples of these scripts, by name, so that we can see these
> uses in context? That might help us figure out a patch that will get
> us out of this mess.
As an example, in one of my scripts I need a date stamp for the current
day. The twist is, days start at 05:30 in the morning (tv-guide like):
today=`date -d "5 hours 30 minutes ago" "+%Y-%m-%d"`
Sure, I can rephrase it to "-330 minutes" but the point stays that
this syntax was fine for a very long time.
Well, I've modified the patch to treat 'yesterday', 'tomorrow' and
'today' special. They now set an additional displacement of -1, +1
and 0 days respectively which is unaffected by 'ago'. They are
not cummulative, the last one wins. One side effect: previously
a number in front of these keywords was accepted and gave some
strange results. Now, the number is kept alone.
Ciao, ET.
diff -rup coreutils-5.94.orig/tests/misc/date coreutils-5.94/tests/misc/date
--- coreutils-5.94.orig/tests/misc/date 2005-09-24 09:57:36 +0200
+++ coreutils-5.94/tests/misc/date 2006-04-26 02:17:24 +0200
@@ -109,6 +109,9 @@ my @Tests =
['rel-3a', "-d '$d1 4 seconds ago' $fmt", {OUT=>"$d0 08:17:44"}],
+ ['rel-4a', "-d '$d1 1 hour 30 minutes ago' $fmt", {OUT=>"$d0 06:47:48"}],
+ ['rel-4b', "-d '$d1 yesterday 1 hour 30 minutes ago' $fmt",
{OUT=>"1997-01-18 06:47:48"}],
+
['next-s', "-d '$d1 next second' '+%Y-%m-%d %T'", {OUT=>"$d0 $ts"}],
['next-m', "-d '$d1 next minute' '+%Y-%m-%d %T'", {OUT=>"$d0 $tm"}],
['next-h', "-d '$d1 next hour' '+%Y-%m-%d %T'", {OUT=>"$d0 $th"}],
diff -rup coreutils-5.94.orig/lib/getdate.y coreutils-5.94/lib/getdate.y
--- coreutils-5.94.orig/lib/getdate.y 2005-08-13 14:10:05 +0200
+++ coreutils-5.94/lib/getdate.y 2006-04-26 03:03:02 +0200
@@ -148,10 +148,11 @@ typedef struct
long int minutes;
long int seconds;
long int ns;
+ long int day_offset;
} relative_time;
#if HAVE_COMPOUND_LITERALS
-# define RELATIVE_TIME_0 ((relative_time) { 0, 0, 0, 0, 0, 0, 0 })
+# define RELATIVE_TIME_0 ((relative_time) { 0, 0, 0, 0, 0, 0, 0, 0 })
#else
static relative_time const RELATIVE_TIME_0;
#endif
@@ -229,7 +230,7 @@ static long int time_zone_hhmm (textint,
%token tAGO tDST
%token tYEAR_UNIT tMONTH_UNIT tHOUR_UNIT tMINUTE_UNIT tSEC_UNIT
-%token <intval> tDAY_UNIT
+%token <intval> tDAY_UNIT tDAY_OFFSET
%token <intval> tDAY tDAYZONE tLOCAL_ZONE tMERIDIAN
%token <intval> tMONTH tORDINAL tZONE
@@ -454,15 +455,15 @@ date:
;
rel:
- relunit tAGO
+ rel tAGO
{
- pc->rel.ns -= $1.ns;
- pc->rel.seconds -= $1.seconds;
- pc->rel.minutes -= $1.minutes;
- pc->rel.hour -= $1.hour;
- pc->rel.day -= $1.day;
- pc->rel.month -= $1.month;
- pc->rel.year -= $1.year;
+ pc->rel.ns *= -1;
+ pc->rel.seconds *= -1;
+ pc->rel.minutes *= -1;
+ pc->rel.hour *= -1;
+ pc->rel.day *= -1;
+ pc->rel.month *= -1;
+ pc->rel.year *= -1;
}
| relunit
{
@@ -474,6 +475,7 @@ rel:
pc->rel.month += $1.month;
pc->rel.year += $1.year;
}
+ | tDAY_OFFSET { pc->rel.day_offset = $1; }
;
relunit:
@@ -663,9 +665,9 @@ static table const time_units_table[] =
/* Assorted relative-time words. */
static table const relative_time_table[] =
{
- { "TOMORROW", tDAY_UNIT, 1 },
- { "YESTERDAY",tDAY_UNIT, -1 },
- { "TODAY", tDAY_UNIT, 0 },
+ { "TOMORROW", tDAY_OFFSET, 1 },
+ { "YESTERDAY",tDAY_OFFSET, -1 },
+ { "TODAY", tDAY_OFFSET, 0 },
{ "NOW", tDAY_UNIT, 0 },
{ "LAST", tORDINAL, -1 },
{ "THIS", tORDINAL, 0 },
@@ -1425,14 +1427,16 @@ get_date (struct timespec *result, char
}
/* Add relative date. */
- if (pc.rel.year | pc.rel.month | pc.rel.day)
+ if (pc.rel.year | pc.rel.month | pc.rel.day | pc.rel.day_offset)
{
int year = tm.tm_year + pc.rel.year;
int month = tm.tm_mon + pc.rel.month;
- int day = tm.tm_mday + pc.rel.day;
+ int day1 = tm.tm_mday + pc.rel.day;
+ int day = day1 + pc.rel.day_offset;
if (((year < tm.tm_year) ^ (pc.rel.year < 0))
| ((month < tm.tm_mon) ^ (pc.rel.month < 0))
- | ((day < tm.tm_mday) ^ (pc.rel.day < 0)))
+ | ((day1 < tm.tm_mday) ^ (pc.rel.day < 0))
+ | ((day < day1) ^ (pc.rel.day_offset < 0)))
goto fail;
tm.tm_year = year;
tm.tm_mon = month;
diff -rup coreutils-5.94.orig/doc/getdate.texi coreutils-5.94/doc/getdate.texi
--- coreutils-5.94.orig/doc/getdate.texi 2005-05-11 22:27:11 +0200
+++ coreutils-5.94/doc/getdate.texi 2006-04-26 02:44:54 +0200
@@ -345,6 +345,7 @@ examples:
1 year ago
3 years
2 days
+1 hour 30 minutes ago
@end example
@findex year @r{in date strings}
@@ -363,19 +364,22 @@ days, @samp{day} worth 24 hours, @samp{h
@samp{sec} worth one second. An @samp{s} suffix on these units is
accepted and ignored.
address@hidden ago @r{in date strings}
The unit of time may be preceded by a multiplier, given as an optionally
signed number. Unsigned numbers are taken as positively signed. No
-number at all implies 1 for a multiplier. Following a relative item by
-the string @samp{ago} is equivalent to preceding the unit by a
-multiplier with value @math{-1}.
+number at all implies 1 for a multiplier.
+
address@hidden ago @r{in date strings}
+The string @samp{ago} multiplies the accumulated time displacement to
+its left with the value @math{-1}. For example, @samp{1 hour 30 minutes
+ago} is the same as @samp{-90 minutes}.
address@hidden day @r{in date strings}
@findex tomorrow @r{in date strings}
@findex yesterday @r{in date strings}
-The string @samp{tomorrow} is worth one day in the future (equivalent
-to @samp{day}), the string @samp{yesterday} is worth
-one day in the past (equivalent to @samp{day ago}).
address@hidden today @r{in date strings}
+The string @samp{tomorrow} adjusts the displacement by one day in the
+future, the string @samp{yesterday} one day in the past and the string
address@hidden cancels a previous @samp{tomorrow/yesterday}. The adjustment
+performed by @samp{tomorrow/yesterday} is not affected by @samp{ago}.
@findex now @r{in date strings}
@findex today @r{in date strings}
- r1.100 of getdate.y changed 'ago' behavior, Mike Frysinger, 2006/04/19
- Re: r1.100 of getdate.y changed 'ago' behavior, Paul Eggert, 2006/04/20
- Re: r1.100 of getdate.y changed 'ago' behavior, The Wanderer, 2006/04/20
- Re: r1.100 of getdate.y changed 'ago' behavior, Edgar Toernig, 2006/04/25
- Re: r1.100 of getdate.y changed 'ago' behavior, Paul Eggert, 2006/04/25
- Re: r1.100 of getdate.y changed 'ago' behavior,
Edgar Toernig <=
- Message not available
- Message not available
- Message not available
- Message not available
- Message not available
- Re: r1.100 of getdate.y changed 'ago' behavior, Edgar Toernig, 2006/04/26
- Re: r1.100 of getdate.y changed 'ago' behavior, James Youngman, 2006/04/28