[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] date: accept 'hence' as opposite of 'ago'
From: |
Eric Blake |
Subject: |
[PATCH] date: accept 'hence' as opposite of 'ago' |
Date: |
Fri, 16 Sep 2011 14:59:04 -0600 |
* lib/parse-datetime.y (relative_time_table): Add 'hence'.
* tests/test-parse-datetime.c (main): Enhance test.
Suggested by Jesse Wilson.
Signed-off-by: Eric Blake <address@hidden>
---
> Since you've already got "AGO", it makes a great deal of sense to add
> "HENCE" to parse-datetime so we can change the date like this:
>
> date -d "2 years hence"
>
> Hence is definitely the antonym of ago, so this is a good idea.
I like it.
> I
> tried to write the patch myself, but I found parse-datetime.c to be
> too complex for me to be able to figure out quickly.
That was your problem. Editing parse-datetime.y and letting bison
regenerate parse-datetime.c is by far the better way to do things. :)
ChangeLog | 5 +++++
lib/parse-datetime.y | 8 +++++---
tests/test-parse-datetime.c | 7 +++++++
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1da8266..400b387 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2011-09-16 Eric Blake <address@hidden>
+ date: accept 'hence' as opposite of 'ago'
+ * lib/parse-datetime.y (relative_time_table): Add 'hence'.
+ * tests/test-parse-datetime.c (main): Enhance test.
+ Suggested by Jesse Wilson.
+
fdatasync: port to Solaris
* m4/fdatasync.m4 (gl_FUNC_FDATASYNC): Set LIB_FDATASYNC.
* modules/fdatasync (Link): Document it.
diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y
index 33ef01a..d99c955 100644
--- a/lib/parse-datetime.y
+++ b/lib/parse-datetime.y
@@ -296,7 +296,8 @@ set_hhmmss (parser_control *pc, long int hour, long int
minutes,
relative_time rel;
}
-%token tAGO tDST
+%token <intval> tAGO
+%token tDST
%token tYEAR_UNIT tMONTH_UNIT tHOUR_UNIT tMINUTE_UNIT tSEC_UNIT
%token <intval> tDAY_UNIT tDAY_SHIFT
@@ -544,7 +545,7 @@ iso_8601_date:
rel:
relunit tAGO
- { apply_relative_time (pc, $1, -1); }
+ { apply_relative_time (pc, $1, $2); }
| relunit
{ apply_relative_time (pc, $1, 1); }
| dayshift
@@ -733,7 +734,8 @@ static table const relative_time_table[] =
{ "TENTH", tORDINAL, 10 },
{ "ELEVENTH", tORDINAL, 11 },
{ "TWELFTH", tORDINAL, 12 },
- { "AGO", tAGO, 1 },
+ { "AGO", tAGO, -1 },
+ { "HENCE", tAGO, 1 },
{ NULL, 0, 0 }
};
diff --git a/tests/test-parse-datetime.c b/tests/test-parse-datetime.c
index ac408cc..b9d08a6 100644
--- a/tests/test-parse-datetime.c
+++ b/tests/test-parse-datetime.c
@@ -327,6 +327,8 @@ main (int argc _GL_UNUSED, char **argv)
ASSERT (!parse_datetime (&result, p, &now));
p = "UTC+4:00 tomorrow ago";
ASSERT (!parse_datetime (&result, p, &now));
+ p = "UTC+4:00 tomorrow hence";
+ ASSERT (!parse_datetime (&result, p, &now));
p = "UTC+4:00 40 now ago";
ASSERT (!parse_datetime (&result, p, &now));
p = "UTC+4:00 last tomorrow";
@@ -345,6 +347,11 @@ main (int argc _GL_UNUSED, char **argv)
LOG (p, now, result2);
ASSERT (result.tv_sec == result2.tv_sec
&& result.tv_nsec == result2.tv_nsec);
+ p = "UTC+400 1 day hence";
+ ASSERT (parse_datetime (&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";
--
1.7.4.4
- [PATCH] date: accept 'hence' as opposite of 'ago',
Eric Blake <=