Revision: 57205
          http://sourceforge.net/p/brlcad/code/57205
Author:   brlcad
Date:     2013-08-28 03:34:17 +0000 (Wed, 28 Aug 2013)
Log Message:
-----------
instead of a completely different string, how about instead returning a 'null' 
time entry ala SQL.  this way it's formatted correctly and can be evaluated as 
an error, but is otherwise syntactically safe/consistent if anything is set up 
to parse the result.

Modified Paths:
--------------
    brlcad/trunk/src/libbu/date-time.c

Modified: brlcad/trunk/src/libbu/date-time.c
===================================================================
--- brlcad/trunk/src/libbu/date-time.c  2013-08-28 03:31:56 UTC (rev 57204)
+++ brlcad/trunk/src/libbu/date-time.c  2013-08-28 03:34:17 UTC (rev 57205)
@@ -20,18 +20,16 @@
 
 #include "common.h"
 
-/*
-#include <stdio.h>
+#include <time.h>
 #include <string.h>
-*/
 
-#include <time.h>
-
 #include "bu.h"
 
+
 void
 bu_utctime(struct bu_vls *vls_gmtime)
 {
+    static const char *nulltime = "0000-00-00T00:00:00Z";
     struct tm loctime;
     struct tm* retval;
     time_t curr_time;
@@ -43,20 +41,23 @@
 
     curr_time = time(0);
     if (curr_time == (time_t)(-1)) {
-       /* time error: but set something */
-       bu_vls_sprintf(vls_gmtime, "TIME_ERROR");
+       /* time error: but set something, an invalid "NULL" time. */
+       bu_vls_sprintf(vls_gmtime, nulltime);
        return;
     }
 
+    memset(&loctime, 0, sizeof(loctime));
+
     bu_semaphore_acquire(BU_SEM_DATETIME);
     retval = gmtime(&curr_time);
-    loctime = *retval; /* struct copy */
+    if (retval)
+       loctime = *retval; /* struct copy */
     bu_semaphore_release(BU_SEM_DATETIME);
 
     /* put the UTC time in the desired ISO format: "yyyy-mm-ddThh:mm:ssZ" */
     bu_vls_sprintf(vls_gmtime, "%04d-%02d-%02dT%02d:%02d:%02dZ",
-                  loctime.tm_year + 1900,
-                  loctime.tm_mon + 1,
+                  loctime.tm_year > 0 ? loctime.tm_year + 1900 : 
loctime.tm_year,
+                  loctime.tm_mon > 0 ? loctime.tm_mon + 1 : loctime.tm_mon,
                   loctime.tm_mday,
                   loctime.tm_hour,
                   loctime.tm_min,

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to