From 526c0de4383f29d98b71511d18fed0c0e9272b55 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?=
Date: Fri, 26 Sep 2008 15:28:49 +0200
Subject: [PATCH] getdate.y: Do not allow countable general dayshifts
* lib/getdate.y (relative_time_table) : New type tDAY_SHIFT
for exactly specified dayshifts added and used
* tests/test-getdate.c : Tests for no longer allowed countable
dayshifts (e.g. 4 yesterday ago) added.
---
ChangeLog | 7 +++++++
lib/getdate.y | 19 +++++++++++++------
tests/test-getdate.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 07f0026..d204816 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-09-27 Ondrej Vasik
+ getdate.y: Do not allow countable general dayshifts
+ * lib/getdate.y (relative_time_table) : New type tDAY_SHIFT
+ for exactly specified dayshifts added and used
+ * tests/test-getdate.c : Tests for no longer allowed countable
+ dayshifts (e.g. 4 yesterday ago) added.
+
2008-09-26 Jim Meyering
fts: tweak inode comparison function
diff --git a/lib/getdate.y b/lib/getdate.y
index f9cd86c..877b264 100644
--- a/lib/getdate.y
+++ b/lib/getdate.y
@@ -293,7 +293,7 @@ set_hhmmss (parser_control *pc, long int hour, long int minutes,
%token tAGO tDST
%token tYEAR_UNIT tMONTH_UNIT tHOUR_UNIT tMINUTE_UNIT tSEC_UNIT
-%token tDAY_UNIT
+%token tDAY_UNIT tDAY_SHIFT
%token tDAY tDAYZONE tLOCAL_ZONE tMERIDIAN
%token tMONTH tORDINAL tZONE
@@ -304,7 +304,7 @@ set_hhmmss (parser_control *pc, long int hour, long int minutes,
%type o_colon_minutes o_merid
%type seconds signed_seconds unsigned_seconds
-%type relunit relunit_snumber
+%type relunit relunit_snumber dayshift
%%
@@ -502,6 +502,8 @@ rel:
{ apply_relative_time (pc, $1, -1); }
| relunit
{ apply_relative_time (pc, $1, 1); }
+ | dayshift
+ { apply_relative_time (pc, $1, 1); }
;
relunit:
@@ -563,6 +565,11 @@ relunit_snumber:
{ $$ = RELATIVE_TIME_0; $$.seconds = $1.value; }
;
+dayshift:
+ tDAY_SHIFT
+ { $$ = RELATIVE_TIME_0; $$.day = $1; }
+ ;
+
seconds: signed_seconds | unsigned_seconds;
signed_seconds:
@@ -669,10 +676,10 @@ 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 },
- { "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 },
diff --git a/tests/test-getdate.c b/tests/test-getdate.c
index 80cf573..5edda4b 100644
--- a/tests/test-getdate.c
+++ b/tests/test-getdate.c
@@ -161,5 +161,53 @@ main (int argc, char **argv)
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;
}
--
1.5.6.1.156.ge903b