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

[PATCH] Unify human represented timestamp formats.

From: Nuutti Kotivuori <naked_at_iki.fi>
Date: 2002-06-22 12:08:37 CEST

I made a patch which adds a new function, svn_time_to_human_nts, and
then uses it for the places where the date format is mangled for user
display.

The actual format of the date stamps is:
2002-06-22 11:14:42 +03:00

The format can - and should - be changed if a real consensus is gotten
for the format.

The dubious part is 'svnlook'. Should that use this same function?
This means that TZ needs to be set very carefully for it. I'd want
some input on this.

I'll probably work a bit more on the patch - and then commit it if it
is deemed as a good thing. But, without further ado, on to examples
and the patch.

Examples:

naked@oro:~/src/subversion/svn$ svn log -r2307
------------------------------------------------------------------------
rev 2307: brane | 2002-06-21 23:39:28 +03:00 | 1 line

* subversion_client.dsp: Removed trace-update.c.
------------------------------------------------------------------------

naked@oro:~/src/subversion/svn$ TZ= svn log -r2307
------------------------------------------------------------------------
rev 2307: brane | 2002-06-21 20:39:28 +00:00 | 1 line

* subversion_client.dsp: Removed trace-update.c.
------------------------------------------------------------------------

naked@oro:~/src/subversion/svn$ TZ=MST svn log -r2307
------------------------------------------------------------------------
rev 2307: brane | 2002-06-21 13:39:28 -07:00 | 1 line

* subversion_client.dsp: Removed trace-update.c.
------------------------------------------------------------------------

naked@oro:~/src/subversion/svn$ svn info
Path: .
Url: http://svn.collab.net/repos/svn/trunk
Revision: 2308
Node Kind: directory
Schedule: normal
Last Changed Author: naked
Last Changed Rev: 2308
Last Changed Date: 2002-06-22 11:14:42 +03:00
Properties Last Updated: 2002-06-09 14:35:13 +03:00

naked@oro:/tmp/repostemp$ svnlook foorepos

2002-06-22 12:14:58 +03:00
0
/

Log message:
Added a new function, svn_time_to_human_nts, that handles converting
apr_time_t into a human representable time format. Then made 'svn log',
'svn info' and 'svnlook' use it.

* subversion/include/svn_time.h
(svn_time_to_human_nts): New prototype.

* subversion/libsvn_subr/time.c
(human_timestamp_format): New variable.
(svn_time_to_human_nts): New function.

* subversion/svnlook/main.c
(do_date): Use svn_time_to_human_nts.

* subversion/clients/cmdline/log-cmd.c: Include svn_time.h.
(humanize_date): Remove function.
(log_message_receiver): Use svn_time_to_human_nts.

* subversion/clients/cmdline/info-cmd.c: Include svn_time.h.
(svn_cl__info_print_time): Add pool argument.
(svn_cl__info_print_time): Use svn_time_to_human_nts.
(svn_cl__info): Give pool to svn_cl__info_print_time.

Patch:
Index: ./subversion/include/svn_time.h
===================================================================
--- ./subversion/include/svn_time.h
+++ ./subversion/include/svn_time.h Sat Jun 22 11:44:59 2002
@@ -39,6 +39,11 @@
 svn_error_t *svn_time_from_nts(apr_time_t *when, const char *data,
                                apr_pool_t *pool);
 
+/* Convert WHEN to a const char * representation allocated in POOL,
+ suitable for human display. */
+const char *svn_time_to_human_nts (apr_time_t when, apr_pool_t *pool);
+
+
 /* Needed by getdate.y parser */
 struct getdate_time {
   time_t time;
Index: ./subversion/libsvn_subr/time.c
===================================================================
--- ./subversion/libsvn_subr/time.c
+++ ./subversion/libsvn_subr/time.c Sat Jun 22 12:48:28 2002
@@ -55,6 +55,16 @@
 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:
+ *
+ * "2002-05-07 12:34:56 +03:00"
+ *
+ * This format is used whenever time is shown to the user
+ * directly.
+ */
+static const char * const human_timestamp_format =
+"%.4d-%.2d-%.2d %.2d:%.2d:%.2d %+.2d:%.2d";
+
 
 const char *
 svn_time_to_nts (apr_time_t t, apr_pool_t *pool)
@@ -193,6 +203,26 @@
       return svn_error_createf(SVN_ERR_BAD_DATE, 0, NULL, pool,
                                "Date parsing failed.");
     }
+}
+
+
+const char *
+svn_time_to_human_nts (apr_time_t t, apr_pool_t *pool)
+{
+ apr_time_exp_t exploded_time;
+
+ apr_time_exp_lt (&exploded_time, t);
+
+ return apr_psprintf (pool,
+ 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);
 }
 
 
Index: ./subversion/svnlook/main.c
===================================================================
--- ./subversion/svnlook/main.c
+++ ./subversion/svnlook/main.c Sat Jun 22 12:13:14 2002
@@ -736,28 +736,11 @@
 
       if (prop_value && prop_value->data)
         {
- /* The date stored in the repository is in a really complex
- and precise format...and we don't care. Let's convert
- that to just "YYYY-MM-DD hh:mm".
-
- ### todo: Right now, "svn dates" are not GMT, but the
- results of svn_time_from_string are. This sucks. */
- apr_time_exp_t extime;
+ /* Convert the date for humans. */
           apr_time_t aprtime;
- apr_status_t apr_err;
           
           SVN_ERR (svn_time_from_nts (&aprtime, prop_value->data, pool));
- apr_err = apr_time_exp_tz (&extime, aprtime, 0);
- if (apr_err)
- return svn_error_create (apr_err, 0, NULL, pool,
- "do_date: error exploding time");
-
- printf ("%04lu-%02lu-%02lu %02lu:%02lu GMT",
- (unsigned long)(extime.tm_year + 1900),
- (unsigned long)(extime.tm_mon + 1),
- (unsigned long)(extime.tm_mday),
- (unsigned long)(extime.tm_hour),
- (unsigned long)(extime.tm_min));
+ printf ("%s", svn_time_to_human_nts (aprtime, pool));
         }
     }
 
Index: ./subversion/clients/cmdline/log-cmd.c
===================================================================
--- ./subversion/clients/cmdline/log-cmd.c
+++ ./subversion/clients/cmdline/log-cmd.c Sat Jun 22 12:07:30 2002
@@ -34,6 +34,7 @@
 #include "svn_pools.h"
 #include "svn_sorts.h"
 #include "svn_xml.h"
+#include "svn_time.h"
 #include "cl.h"
 
 
@@ -79,47 +80,6 @@
 };
 
 
-/* Maximum length of a human-readable date string, including final '\0'. */
-#define SVN_LOG__DATE_MAX 38
-
-
-/* Format an svn_time_to_string()-created date for human consumption,
- * store the result in RESULT, which is at least SVN_LOG__DATE_MAX
- * bytes long.
- *
- * Why do this? The problem is that svn_time_to_string() returns a
- * date like this:
- *
- * "Sat 2 Mar 2002 20:41:01.695108 (day 061, dst 0, gmt_off -21600)"
- *
- * but humans only want to see:
- *
- * "Sat 2 Mar 2002 20:41:01"
- *
- * You would think the part before the dot would be constant length,
- * but it's not, because the day-of-month can be one or two digits.
- * Also, we want to get the right result unconditionally, even when
- * handed an already-truncated date. So, we have this function to
- * sort it all out and Do The Right Thing.
- */
-static void
-humanize_date (char *result, const char *date)
-{
- const char *p = strchr (date, '.');
-
- if (p && ((p - date) < SVN_LOG__DATE_MAX))
- {
- strncpy (result, date, (p - date));
- result[p - date] = '\0';
- }
- else /* hmmm, not the format we expected, so use as much as can */
- {
- strncpy (result, date, (SVN_LOG__DATE_MAX - 1));
- result[SVN_LOG__DATE_MAX - 1] = '\0';
- }
-}
-
-
 /* This implements `svn_log_message_receiver_t', printing the logs in
  * a human-readable and machine-parseable format. BATON is of type
  * `struct log_message_receiver_baton *'.
@@ -159,8 +119,8 @@
   /* Number of lines in the msg. */
   int lines;
 
- /* As much date as we ever want to see. */
- char dbuf[SVN_LOG__DATE_MAX];
+ /* Date string for humans. */
+ const char *dbuf;
 
   if (rev == 0)
     {
@@ -168,7 +128,13 @@
       return SVN_NO_ERROR;
     }
 
- humanize_date (dbuf, date);
+ {
+ /* Convert date to a format for humans. */
+ apr_time_t time_temp;
+
+ SVN_ERR (svn_time_from_nts (&time_temp, date, pool));
+ dbuf = svn_time_to_human_nts(time_temp, pool);
+ }
 
 #define SEP_STRING \
   "------------------------------------------------------------------------\n"
Index: ./subversion/clients/cmdline/info-cmd.c
===================================================================
--- ./subversion/clients/cmdline/info-cmd.c
+++ ./subversion/clients/cmdline/info-cmd.c Sat Jun 22 12:10:50 2002
@@ -26,26 +26,18 @@
 #include "svn_string.h"
 #include "svn_error.h"
 #include "svn_path.h"
+#include "svn_time.h"
 #include "cl.h"
 
 
 /*** Code. ***/
 
 static void
-svn_cl__info_print_time (apr_time_t atime, const char * desc)
+svn_cl__info_print_time (apr_time_t atime,
+ const char *desc,
+ apr_pool_t *pool)
 {
- apr_time_exp_t extime;
- apr_status_t apr_err;
-
- /* if this returns an error, just don't print anything out */
- apr_err = apr_time_exp_tz (&extime, atime, 0);
- if (! apr_err)
- printf ("%s: %04lu-%02lu-%02lu %02lu:%02lu GMT\n", desc,
- (unsigned long)(extime.tm_year + 1900),
- (unsigned long)(extime.tm_mon + 1),
- (unsigned long)(extime.tm_mday),
- (unsigned long)(extime.tm_hour),
- (unsigned long)(extime.tm_min));
+ printf ("%s: %s\n", desc, svn_time_to_human_nts (atime,pool));
 }
 
 svn_error_t *
@@ -161,13 +153,14 @@
         printf ("Last Changed Rev: %" SVN_REVNUM_T_FMT "\n", entry->cmt_rev);
 
       if (entry->cmt_date)
- svn_cl__info_print_time (entry->cmt_date, "Last Changed Date");
+ svn_cl__info_print_time (entry->cmt_date, "Last Changed Date", pool);
 
       if (entry->text_time)
- svn_cl__info_print_time (entry->text_time, "Text Last Updated");
+ svn_cl__info_print_time (entry->text_time, "Text Last Updated", pool);
 
       if (entry->prop_time)
- svn_cl__info_print_time (entry->prop_time, "Properties Last Updated");
+ svn_cl__info_print_time (entry->prop_time, "Properties Last Updated",
+ pool);
 
       if (entry->checksum)
         printf ("Checksum: %s\n", entry->checksum);

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Jun 22 12:10:54 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.