+2008-09-29 Ondřej Vašík <ovasik@redhat.com>
+
+ getdate.y: disallow countable dayshifts like "4 yesterday ago"
+ * lib/getdate.y (relative_time_table) [tDAY_SHIFT]: New type for
+ exactly specified dayshifts.
+ (dayshift): New rule.
+ (rel): Add dayshift.
+ (relative_time_table) [tomorrow, yesterday, today, now]:
+ Use tDAY_SHIFT in place of tDAY_UNIT.
+ * tests/test-getdate.c: Add tests for now-disallowed countable
+ dayshifts, e.g., "4 yesterday ago".
+
2008-09-29 Bruno Haible <bruno@clisp.org>
* tests/test-posix_spawn1.c: Renamed from tests/test-posix_spawn.c.
%token tAGO tDST
%token tYEAR_UNIT tMONTH_UNIT tHOUR_UNIT tMINUTE_UNIT tSEC_UNIT
-%token <intval> tDAY_UNIT
+%token <intval> tDAY_UNIT tDAY_SHIFT
%token <intval> tDAY tDAYZONE tLOCAL_ZONE tMERIDIAN
%token <intval> tMONTH tORDINAL tZONE
%type <intval> o_colon_minutes o_merid
%type <timespec> seconds signed_seconds unsigned_seconds
-%type <rel> relunit relunit_snumber
+%type <rel> relunit relunit_snumber dayshift
%%
{ apply_relative_time (pc, $1, -1); }
| relunit
{ apply_relative_time (pc, $1, 1); }
+ | dayshift
+ { apply_relative_time (pc, $1, 1); }
;
relunit:
{ $$ = RELATIVE_TIME_0; $$.seconds = $1.value; }
;
+dayshift:
+ tDAY_SHIFT
+ { $$ = RELATIVE_TIME_0; $$.day = $1; }
+ ;
+
seconds: signed_seconds | unsigned_seconds;
signed_seconds:
/* Assorted relative-time words. */
static table const relative_time_table[] =
{
- { "TOMORROW", tDAY_UNIT, 1 },
- { "YESTERDAY",tDAY_UNIT, -1 },
- { "TODAY", tDAY_UNIT, 0 },
- { "NOW", tDAY_UNIT, 0 },
+ { "TOMORROW", tDAY_SHIFT, 1 },
+ { "YESTERDAY",tDAY_SHIFT, -1 },
+ { "TODAY", tDAY_SHIFT, 0 },
+ { "NOW", tDAY_SHIFT, 0 },
{ "LAST", tORDINAL, -1 },
{ "THIS", tORDINAL, 0 },
{ "NEXT", tORDINAL, 1 },
p = "UTC+25:00";
ASSERT (!get_date (&result, p, &now));
+ /* Check for several invalid countable dayshifts */
+ now.tv_sec = 4711;
+ now.tv_nsec = 1267;
+ p = "UTC+4:00 +40 yesterday";
+ ASSERT (!get_date (&result, p, &now));
+ p = "UTC+4:00 next yesterday";
+ ASSERT (!get_date (&result, p, &now));
+ p = "UTC+4:00 tomorrow ago";
+ ASSERT (!get_date (&result, p, &now));
+ p = "UTC+4:00 40 now ago";
+ ASSERT (!get_date (&result, p, &now));
+ p = "UTC+4:00 last tomorrow";
+ ASSERT (!get_date (&result, p, &now));
+ p = "UTC+4:00 -4 today";
+ ASSERT (!get_date (&result, p, &now));
+
+ /* And check correct usage of dayshifts */
+ now.tv_sec = 4711;
+ now.tv_nsec = 1267;
+ p = "UTC+400 tomorrow";
+ ASSERT (get_date (&result, p, &now));
+ LOG (p, now, result);
+ p = "UTC+400 +1 day";
+ ASSERT (get_date (&result2, p, &now));
+ LOG (p, now, result2);
+ ASSERT (result.tv_sec == result2.tv_sec
+ && result.tv_nsec == result2.tv_nsec);
+ now.tv_sec = 4711;
+ now.tv_nsec = 1267;
+ p = "UTC+400 yesterday";
+ ASSERT (get_date (&result, p, &now));
+ LOG (p, now, result);
+ p = "UTC+400 1 day ago";
+ ASSERT (get_date (&result2, p, &now));
+ LOG (p, now, result2);
+ ASSERT (result.tv_sec == result2.tv_sec
+ && result.tv_nsec == result2.tv_nsec);
+ now.tv_sec = 4711;
+ now.tv_nsec = 1267;
+ p = "UTC+400 now";
+ ASSERT (get_date (&result, p, &now));
+ LOG (p, now, result);
+ p = "UTC+400 +0 minutes"; /* silly, but simple "UTC+400" is different*/
+ ASSERT (get_date (&result2, p, &now));
+ LOG (p, now, result2);
+ ASSERT (result.tv_sec == result2.tv_sec
+ && result.tv_nsec == result2.tv_nsec);
+
return 0;
}