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

[PATCH 1/4] Add parse_date_format() convenience function for converting a format string to an enum date_mode

From
APAndy Parkins <andyparkins@gmail.com>
Date
Sep 28, 2007, 14:17 UTC
Message-ID
<200709281517.26627.andyparkins@gmail.com>
In-Reply-To
<200709281516.05438.andyparkins@gmail.com>

parse_date_format() is passed a string that is compared against a pre-defined list and converted to an enum date_format. The table is as follows:

 - "relative"         => DATE_RELATIVE
 - "iso8601" or "iso" => DATE_ISO8601
 - "rfc2822"          => DATE_RFC2822
 - "short"            => DATE_SHORT
 - "local"            => DATE_LOCAL
 - "default"          => DATE_NORMAL
In the event that none of these strings is found, the function die()s.
Signed-off-by: Andy Parkins <andyparkins@gmail.com>
---
 cache.h |    1 +
 date.c  |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/cache.h b/cache.h
index 8246500..5587f7e 100644
--- a/cache.h
+++ b/cache.h
@@ -432,6 +432,7 @@ const char *show_date(unsigned long time, int timezone, enum date_mode mode);
 int parse_date(const char *date, char *buf, int bufsize);
 void datestamp(char *buf, int bufsize);
 unsigned long approxidate(const char *);
+enum date_mode parse_date_format(const char *format);
 
 extern const char *git_author_info(int);
 extern const char *git_committer_info(int);
diff --git a/date.c b/date.c
index 93bef6e..8f70500 100644
--- a/date.c
+++ b/date.c
@@ -584,6 +584,26 @@ int parse_date(const char *date, char *result, int maxlen)
 	return date_string(then, offset, result, maxlen);
 }
 
+enum date_mode parse_date_format(const char *format)
+{
+	if (!strcmp(format, "relative"))
+		return DATE_RELATIVE;
+	else if (!strcmp(format, "iso8601") ||
+		 !strcmp(format, "iso"))
+		return DATE_ISO8601;
+	else if (!strcmp(format, "rfc2822") ||
+		 !strcmp(format, "rfc"))
+		return DATE_RFC2822;
+	else if (!strcmp(format, "short"))
+		return DATE_SHORT;
+	else if (!strcmp(format, "local"))
+		return DATE_LOCAL;
+	else if (!strcmp(format, "default"))
+		return DATE_NORMAL;
+	else
+		die("unknown date format %s", format);
+}
+
 void datestamp(char *buf, int bufsize)
 {
 	time_t now;
-- 
1.5.3.2.105.gf47f2-dirty
Previous: Andy ParkinsNext: Andy Parkins
Message 4 of 15 in “Add a --dateformat= option to git-for-each-ref”
  1. Add a --dateformat= option to git-for-each-refAndy Parkins, Sep 26, 2007
  2. Jeff KingSep 26, 2007
  3. Andy ParkinsSep 28, 2007
  4. 1/4 Add parse_date_format() convenience function for converting a format string to an enum date_modeAndy Parkins, Sep 28, 2007
  5. 2/4 Use parse_date_format() in revisions.c to parse the --date parameterAndy Parkins, Sep 28, 2007
  6. Johannes SchindelinSep 28, 2007
  7. Andy ParkinsSep 28, 2007
  8. Junio C HamanoSep 28, 2007
  9. 1/3 Use parse_date_format() convenience function for converting a format string to an enum date_mode in revisions.cAndy Parkins, Sep 29, 2007
  10. 2/3 Make for-each-ref allow atom names like "<name>:<something>"Andy Parkins, Sep 29, 2007
  11. 3/3 Make for-each-ref's grab_date() support per-atom formattingAndy Parkins, Sep 29, 2007
  12. 3/4 Make for-each-ref allow atom names like "<name>:<something>"Andy Parkins, Sep 28, 2007
  13. 4/4 Make for-each-ref's grab_date() support per-atom formattingAndy Parkins, Sep 28, 2007
  14. Junio C HamanoSep 29, 2007
  15. Jeff KingSep 28, 2007

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.