git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Allow testing of _relative family of time formatting and parsing functions

From
Alex Riesen <raa.lkml@gmail.com>
Date
Aug 28, 2009, 20:52 UTC
Message-ID
<20090828205232.GD9233@blimp.localdomain>
In-Reply-To
<20090828193302.GB9233@blimp.localdomain>

To complement the testability of approxidate. --- Alex Riesen, Fri, Aug 28, 2009 21:33:02 +0200:

> 
> It should allow safe testing of this part of the code.
And this should really allow testing of it:
    $ ./test-date '10.days.ago'
    10.days.ago -> bad -> Thu Jan  1 01:00:00 1970
    10.days.ago -> Tue Aug 18 22:50:20 2009
    relative: 10.days.ago -> Fri Dec 22 12:00:00 1989
    relative: 10 days ago, out of Fri Dec 22 12:00:00 1989
    $

According to Wikipedia, absolutely nothing of note happened at the day 10 January, 1990.

 test-date.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/test-date.c b/test-date.c
index 62e8f23..dcc7973 100644
--- a/test-date.c
+++ b/test-date.c
@@ -4,6 +4,17 @@ int main(int argc, char **argv)
 {
 	int i;
 
+	struct tm tm;
+	struct timeval when = {0, 0};
+	tm.tm_sec  = 0;
+	tm.tm_min  = 0;
+	tm.tm_hour = 12;
+	tm.tm_mday = 1;
+	tm.tm_mon  = 0  /* January */;
+	tm.tm_year = 90 /* 1990 */ ;
+	tm.tm_isdst = -1;
+	when.tv_sec = mktime(&tm);
+
 	for (i = 1; i < argc; i++) {
 		char result[100];
 		time_t t;
@@ -15,6 +26,12 @@ int main(int argc, char **argv)
 
 		t = approxidate(argv[i]);
 		printf("%s -> %s\n", argv[i], ctime(&t));
+
+		t = approxidate_relative(argv[i], &when);
+		printf("relative: %s -> %s\n", argv[i], ctime(&t));
+
+		printf("relative: %s, out of %s\n",
+		       show_date_relative(t, 0, &when), ctime(&t));
 	}
 	return 0;
 }
-- 
1.6.4.1.263.g468a
Previous: Alex RiesenNext: Alex Riesen
Message 24 of 47 in “Round-down years in "years+months" relative date view”
  1. Round-down years in "years+months" relative date viewDavid Reiss, Aug 27, 2009
  2. Jeff KingAug 28, 2009
  3. Alex RiesenAug 28, 2009
  4. Jeff KingAug 28, 2009
  5. Alex RiesenAug 28, 2009
  6. Jeff KingAug 28, 2009
  7. Alex RiesenAug 28, 2009
  8. A Large Angry SCMAug 28, 2009
  9. Nicolas PitreAug 28, 2009
  10. Jeff KingAug 28, 2009
  11. Alex RiesenAug 28, 2009
  12. Jeff KingAug 28, 2009
  13. Alex RiesenAug 28, 2009
  14. Alex RiesenAug 28, 2009
  15. Nicolas PitreAug 28, 2009
  16. Alex RiesenAug 28, 2009
  17. Nicolas PitreAug 28, 2009
  18. Alex RiesenAug 28, 2009
  19. Nicolas PitreAug 28, 2009
  20. Alex RiesenAug 28, 2009
  21. Jeff KingAug 28, 2009
  22. Alex RiesenAug 28, 2009
  23. Alex RiesenAug 28, 2009
  24. Allow testing of _relative family of time formatting and parsing functionsAlex Riesen, Aug 28, 2009
  25. Alex RiesenAug 28, 2009
  26. Junio C HamanoAug 29, 2009
  27. Alex RiesenAug 30, 2009
  28. Jeff KingAug 30, 2009
  29. Alex RiesenAug 30, 2009
  30. 1/2 Add date formatting and parsing functions relative to a given timeAlex Riesen, Aug 30, 2009
  31. 2/2 Allow testing of _relative family of time formatting and parsing functionsAlex Riesen, Aug 30, 2009
  32. Jeff KingAug 30, 2009
  33. Jeff KingAug 30, 2009
  34. Alex RiesenAug 30, 2009
  35. Jeff KingAug 30, 2009
  36. Alex RiesenAug 30, 2009
  37. 1/3 Add date formatting and parsing functions relative to a given timeJeff King, Aug 30, 2009
  38. Jeff KingAug 30, 2009
  39. Jeff KingAug 31, 2009
  40. 1/4 Add date formatting and parsing functions relative to a given timeJeff King, Aug 31, 2009
  41. Alex RiesenAug 31, 2009
  42. 2/4 refactor test-date interfaceJeff King, Aug 31, 2009
  43. 3/4 tests: add date printing and parsing testsJeff King, Aug 31, 2009
  44. Jeff KingSep 1, 2009
  45. 4/4 fix approxidate parsing of relative months and yearsJeff King, Aug 31, 2009
  46. 2/3 refactor test-date interfaceJeff King, Aug 30, 2009
  47. 3/3 tests: add date printing and parsing testsJeff King, Aug 30, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.