]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add in more tests of the date-parsing logic.
authorTim Kientzle <kientzle@gmail.com>
Sat, 21 Feb 2009 07:19:03 +0000 (02:19 -0500)
committerTim Kientzle <kientzle@gmail.com>
Sat, 21 Feb 2009 07:19:03 +0000 (02:19 -0500)
SVN-Revision: 687

tar/test/test_getdate.c

index d75119cc33a5c002f86fdc1bb1921c0c5d0e99e8..4ab7ca51cfc20bbf894f2f7d06ceb8436713c25a 100644 (file)
@@ -25,6 +25,8 @@
 #include "test.h"
 __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_getdate.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $");
 
+#include <time.h>
+
 /*
  * Verify that the getdate() function works.
  */
@@ -33,6 +35,30 @@ time_t get_date(const char *);
 
 DEFINE_TEST(test_getdate)
 {
-       assertEqualInt(0, get_date("Jan 1, 1970 UTC"));
+       time_t now = time(NULL);
+       struct tm tm = *localtime(&now);
+       time_t dayStart = now
+           - ((tm.tm_hour * 60L + tm.tm_min) * 60L + tm.tm_sec);
+
+       assertEqualInt(get_date("Jan 1, 1970 UTC"), 0);
+       assertEqualInt(get_date("7:12:18-0530 4 May 1983"), 420900138);
+       assertEqualInt(get_date("2004/01/29 513 mest"), 1075345980);
+       assertEqualInt(get_date("99/02/17 7pm utc"), 919278000);
+       assertEqualInt(get_date("02/17/99 7:11am est"), 919253460);
+       assertEqualInt(get_date("tomorrow"), now + 24 * 60 * 60);
+       assertEqualInt(get_date("yesterday"), now - 24 * 60 * 60);
+       assertEqualInt(get_date("now + 1 hour"), now + 60 * 60);
+       assertEqualInt(get_date("now + 1 hour + 1 minute"),
+           now + 60 * 60 + 60);
+       /* "tuesday" is the start of the first tuesday after today */
+       assertEqualInt(get_date("tuesday"),
+           dayStart + ((2 - tm.tm_wday + 7) % 7) * 24 * 60 * 60);
+       /* "next tuesday" is one week after "tuesday" */
+       assertEqualInt(get_date("next tuesday"),
+           dayStart + (((2 - tm.tm_wday + 7) % 7) + 7) * 24 * 60 * 60);
+       assertEqualInt(get_date("tomorrow 5:16am"),
+           dayStart + 24 * 60 * 60 + 5 * 60 * 60 + 16 * 60);
+       assertEqualInt(get_date("5:16am tomorrow"),
+           dayStart + 24 * 60 * 60 + 5 * 60 * 60 + 16 * 60);
        /* TODO: Lots more tests here. */
 }