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

[PATCH] Round-down years in "years+months" relative date view

From
DRDavid Reiss <dreiss@facebook.com>
Date
Aug 27, 2009, 23:39 UTC
Message-ID
<4A97193A.8090502@facebook.com>

Previously, a commit from 1 year and 7 months ago would display as "2 years, 7 months ago".

Signed-off-by: David Reiss <dreiss@facebook.com>
---

Here's my test script. Let me know if you'd rather have it as part of the test suite.

#!/bin/sh set -e REPO="git-relative-dates-test" rm -rf "$REPO" mkdir "$REPO" cd "$REPO" git init NOW=`date +%s` env GIT_AUTHOR_DATE=`expr $NOW - \( 365 + 220 \) \* 24 \* 60 \* 60` git commit --allow-empty -m old-commit git log --date=relative

 date.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/date.c b/date.c
index 1de1845..e848d96 100644
--- a/date.c
+++ b/date.c
@@ -137,7 +137,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 		}
 		/* Give years and months for 5 years or so */
 		if (diff < 1825) {
-			unsigned long years = (diff + 183) / 365;
+			unsigned long years = diff / 365;
 			unsigned long months = (diff % 365 + 15) / 30;
 			int n;
 			n = snprintf(timebuf, sizeof(timebuf), "%lu year%s",
-- 
1.6.0.4
Next: Jeff King
Message 1 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.