[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Human representation date format change

From: Nuutti Kotivuori <naked_at_iki.fi>
Date: 2002-07-15 22:12:26 CEST

Ben Collins-Sussman's comments on getting this in before alpha were:

22:48 sussman:#svn => yes please!!!
22:48 sussman:#svn => do it!

So, here it is. While making this, some bugs were found in APR - but
luckily those will not affect here, yet.

Log message:

New human representation timestamp format - changed from

  Mon, 15 Jul 2002 21:06:43 +0300

to

  2002-07-15 21:06:43 +0300 (Mon, 15 Jul 2002)

The latter part format can be made as a configuration option in the
future.

* subversion/libsvn_subr/time.c
(SVN_SUBR__DATE_MAX_LENGTH): New constant.
(human_timestamp_format): Changed format.
(human_timestamp_format_suffix): New variable.
(svn_time_to_human_nts): Changed to use apr_snprintf and apr_strftime
  both to generate the wanted format.

Patch:

Index: ./subversion/libsvn_subr/time.c
===================================================================
--- ./subversion/libsvn_subr/time.c
+++ ./subversion/libsvn_subr/time.c Mon Jul 15 22:59:19 2002
@@ -55,15 +55,27 @@
 static const char * const old_timestamp_format =
 "%s %d %s %d %02d:%02d:%02d.%06d (day %03d, dst %d, gmt_off %06d)";
 
-/* Our human representation of dates look like this:
+/* Our human representation of dates looks like this:
  *
- * "Sun, 23 Jun 2002 11:13:02 +0300"
+ * "2002-06-23 11:13:02 +0300 (Sun, 23 Jun 2002)"
  *
- * This format is used whenever time is shown to the user
- * directly.
+ * This format is used whenever time is shown to the user. It consists
+ * of a machine parseable, almost ISO-8601, part in the beginning -
+ * and a human explanative part at the end. The machine parseable part
+ * is generated strictly by APR and our code, with a apr_snprintf. The
+ * human explanative part is generated by apr_strftime, which means
+ * that it's generation can be affected by locale, it can fail and it
+ * doesn't need to be constant in size. In other words, perfect to be
+ * converted to a configuration option later on.
  */
+/* Maximum length for the date string. */
+#define SVN_SUBR__DATE_MAX_LENGTH 80
+/* Machine parseable part, generated by apr_snprintf. */
 static const char * const human_timestamp_format =
-"%3.3s, %.2d %3.3s %.2d %.2d:%.2d:%.2d %+.2d%.2d";
+"%.4d-%.2d-%.2d %.2d:%.2d:%.2d %+.2d%.2d";
+/* Human explanative part, generated by apr_strftime. */
+static const char * const human_timestamp_format_suffix =
+" (%a, %d %b %Y)";
 
 
 const char *
@@ -209,20 +221,48 @@
 svn_time_to_human_nts (apr_time_t t, apr_pool_t *pool)
 {
   apr_time_exp_t exploded_time;
+ apr_size_t len, retlen;
+ apr_status_t ret;
+ char *datestr, *curptr;
 
+ /* Get the time into parts */
   apr_time_exp_lt (&exploded_time, t);
 
- return apr_psprintf (pool,
- human_timestamp_format,
- apr_day_snames[exploded_time.tm_wday],
- exploded_time.tm_mday,
- apr_month_snames[exploded_time.tm_mon],
- exploded_time.tm_year + 1900,
- exploded_time.tm_hour,
- exploded_time.tm_min,
- exploded_time.tm_sec,
- exploded_time.tm_gmtoff / (60 * 60),
- (exploded_time.tm_gmtoff / 60) % 60);
+ /* Make room for datestring */
+ datestr = apr_palloc(pool, SVN_SUBR__DATE_MAX_LENGTH);
+
+ /* Put in machine parseable part */
+ len = apr_snprintf (datestr,
+ SVN_SUBR__DATE_MAX_LENGTH,
+ human_timestamp_format,
+ exploded_time.tm_year + 1900,
+ exploded_time.tm_mon + 1,
+ exploded_time.tm_mday,
+ exploded_time.tm_hour,
+ exploded_time.tm_min,
+ exploded_time.tm_sec,
+ exploded_time.tm_gmtoff / (60 * 60),
+ (exploded_time.tm_gmtoff / 60) % 60);
+
+ /* If we overfilled the buffer, just return what we got. */
+ if(len >= SVN_SUBR__DATE_MAX_LENGTH)
+ return datestr;
+
+ /* Calculate offset to the end of the machine parseable part. */
+ curptr = datestr + len;
+
+ /* Put in human readable part */
+ ret = apr_strftime (curptr,
+ &retlen,
+ SVN_SUBR__DATE_MAX_LENGTH - len,
+ human_timestamp_format_suffix,
+ &exploded_time);
+
+ /* If there was an error, ensure that the string is zero-terminated. */
+ if (!ret || retlen == 0)
+ curptr = '\0';
+
+ return datestr;
 }
 
 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Jul 15 22:13:56 2002

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.