Skip to content
Browse files

"now - 2 hours" should be the same as "2 hours ago"

This was broken by a mis-parsing of the "2 hours" phrase.
  • Loading branch information...
1 parent e00007f commit 0cc23cefe50e6d7f4e5dff1b794a99a6a547de99 @kientzle kientzle committed Nov 30, 2012
Showing with 7 additions and 4 deletions.
  1. +5 −4 libarchive/archive_getdate.c
  2. +2 −0 libarchive/test/test_archive_getdate.c
View
9 libarchive/archive_getdate.c
@@ -369,8 +369,8 @@ relunitphrase(struct gdstate *gds)
&& gds->tokenp[1].token == tSEC_UNIT) {
/* "1 day" */
gds->HaveRel++;
- gds->RelSeconds += gds->tokenp[1].value * gds->tokenp[2].value;
- gds->tokenp += 3;
+ gds->RelSeconds += gds->tokenp[0].value * gds->tokenp[1].value;
+ gds->tokenp += 2;
return 1;
}
if (gds->tokenp[0].token == '-'
@@ -403,7 +403,7 @@ relunitphrase(struct gdstate *gds)
/* "now", "tomorrow" */
gds->HaveRel++;
gds->RelSeconds += gds->tokenp[0].value;
- ++gds->tokenp;
+ gds->tokenp += 1;
return 1;
}
if (gds->tokenp[0].token == tMONTH_UNIT) {
@@ -1022,10 +1022,11 @@ int
main(int argc, char **argv)
{
time_t d;
+ time_t now = time(NULL);
while (*++argv != NULL) {
(void)printf("Input: %s\n", *argv);
- d = get_date(*argv);
+ d = get_date(now, *argv);
if (d == -1)
(void)printf("Bad format - couldn't convert.\n");
else
View
2 libarchive/test/test_archive_getdate.c
@@ -43,6 +43,8 @@ DEFINE_TEST(test_archive_getdate)
assertEqualInt(get_date(now, "2004/01/29 513 mest"), 1075345980);
assertEqualInt(get_date(now, "99/02/17 7pm utc"), 919278000);
assertEqualInt(get_date(now, "02/17/99 7:11am est"), 919253460);
+ assertEqualInt(get_date(now, "now - 2 hours"),
+ get_date(now, "2 hours ago"));
/* It's important that we handle ctime() format. */
assertEqualInt(get_date(now, "Sun Feb 22 17:38:26 PST 2009"),
1235353106);

0 comments on commit 0cc23ce

Please sign in to comment.
Something went wrong with that request. Please try again.