Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

"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...
commit 0cc23cefe50e6d7f4e5dff1b794a99a6a547de99 1 parent e00007f
Tim Kientzle kientzle authored
9 libarchive/archive_getdate.c
@@ -369,8 +369,8 @@ relunitphrase(struct gdstate *gds)
369 369 && gds->tokenp[1].token == tSEC_UNIT) {
370 370 /* "1 day" */
371 371 gds->HaveRel++;
372   - gds->RelSeconds += gds->tokenp[1].value * gds->tokenp[2].value;
373   - gds->tokenp += 3;
  372 + gds->RelSeconds += gds->tokenp[0].value * gds->tokenp[1].value;
  373 + gds->tokenp += 2;
374 374 return 1;
375 375 }
376 376 if (gds->tokenp[0].token == '-'
@@ -403,7 +403,7 @@ relunitphrase(struct gdstate *gds)
403 403 /* "now", "tomorrow" */
404 404 gds->HaveRel++;
405 405 gds->RelSeconds += gds->tokenp[0].value;
406   - ++gds->tokenp;
  406 + gds->tokenp += 1;
407 407 return 1;
408 408 }
409 409 if (gds->tokenp[0].token == tMONTH_UNIT) {
@@ -1022,10 +1022,11 @@ int
1022 1022 main(int argc, char **argv)
1023 1023 {
1024 1024 time_t d;
  1025 + time_t now = time(NULL);
1025 1026
1026 1027 while (*++argv != NULL) {
1027 1028 (void)printf("Input: %s\n", *argv);
1028   - d = get_date(*argv);
  1029 + d = get_date(now, *argv);
1029 1030 if (d == -1)
1030 1031 (void)printf("Bad format - couldn't convert.\n");
1031 1032 else
2  libarchive/test/test_archive_getdate.c
@@ -43,6 +43,8 @@ DEFINE_TEST(test_archive_getdate)
43 43 assertEqualInt(get_date(now, "2004/01/29 513 mest"), 1075345980);
44 44 assertEqualInt(get_date(now, "99/02/17 7pm utc"), 919278000);
45 45 assertEqualInt(get_date(now, "02/17/99 7:11am est"), 919253460);
  46 + assertEqualInt(get_date(now, "now - 2 hours"),
  47 + get_date(now, "2 hours ago"));
46 48 /* It's important that we handle ctime() format. */
47 49 assertEqualInt(get_date(now, "Sun Feb 22 17:38:26 PST 2009"),
48 50 1235353106);

0 comments on commit 0cc23ce

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