Hi Jim,

Jim Meyering wrote:
> However, there's a simple work-around: simply to drop the "+", e.g.,
> 
>   $ date -d '20050101 1 day'
>   Sun Jan  2 00:00:00 CST 2005

Yes, I know about that work-around, you could use unsigned offset/
unsigned offset ago as work-around, but the behaviour still differs
from the others for that format - and that's imho wrong.

> In any case, I couldn't accept that patch, because it would allow
> the YYYYMMDD syntax anywhere get_date currently accepts a "rel"
> (relative offset) non-terminal.

Sorry, that was my fault, but it had nothing to do with nonterminal
"rel" -I used pc->dates_seen=true; instead pc->dates_seen++; and that
allowed usage of more date inputs(made dates_seen non-terminal). Sorry
for that error, have to check my patches more carefully next time.

I improved previous patch, created hybrid section - as is more clean
to have such things out of common sections (maybe same thing from "zone"
section should be moved here - of course with pc->zones_seen++) and used
the same code as is in "number" section + relative signed offset code. 

This should solve your objection. Is the patch now acceptable?

Greetings,
         Ondrej Vasik
diff -urp coreutils-6.9.orig/lib/getdate.y coreutils-6.9/lib/getdate.y
--- coreutils-6.9.orig/lib/getdate.y	2007-02-23 19:25:21.000000000 +0100
+++ coreutils-6.9/lib/getdate.y	2007-11-17 09:31:07.000000000 +0100
@@ -268,6 +268,7 @@ item:
   | rel
       { pc->rels_seen = true; }
   | number
+  | hybrid
   ;
 
 time:
@@ -577,6 +578,52 @@ number:
 	  }
       }
   ;
+hybrid:
+   tUNUMBER relunit_snumber
+      {
+	 /* Hybrid between date and relative for YYYYMMDD/YYMMDD date format
+	   for which was YYYYMMDD +X days considered as wrong format */
+	if (pc->dates_seen && ! pc->year.digits
+	    && ! pc->rels_seen && (pc->times_seen || 2 < $1.digits))
+	  pc->year = $1;
+	else
+	  {
+	    if (4 < $1.digits)
+	      {
+		pc->dates_seen++;
+		pc->day = $1.value % 100;
+		pc->month = ($1.value / 100) % 100;
+		pc->year.value = $1.value / 10000;
+		pc->year.digits = $1.digits - 4;
+	      }
+	    else
+	      {
+		pc->times_seen++;
+		if ($1.digits <= 2)
+		  {
+		    pc->hour = $1.value;
+		    pc->minutes = 0;
+		  }
+		else
+		  {
+		    pc->hour = $1.value / 100;
+		    pc->minutes = $1.value % 100;
+		  }
+		pc->seconds.tv_sec = 0;
+		pc->seconds.tv_nsec = 0;
+		pc->meridian = MER24;
+	      }
+	  }
+	 pc->rel.ns += $2.ns;
+	 pc->rel.seconds += $2.seconds;
+	 pc->rel.minutes += $2.minutes;
+	 pc->rel.hour += $2.hour;
+	 pc->rel.day += $2.day;
+	 pc->rel.month += $2.month;
+	 pc->rel.year += $2.year;
+	 pc->rels_seen = true; 
+      }
+		;	
 
 o_colon_minutes:
     /* empty */

Attachment: signature.asc
Description: Toto je digitálně podepsaná část zprávy

_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to