r16016 - gnucash/trunk/src/app-utils - Add gnc_parse_time_to_timet, a concatenation of strptime and mktime.

Andreas Köhler andi5 at cvs.gnucash.org
Sat Apr 28 15:13:45 EDT 2007


Author: andi5
Date: 2007-04-28 15:13:43 -0400 (Sat, 28 Apr 2007)
New Revision: 16016
Trac: http://svn.gnucash.org/trac/changeset/16016

Modified:
   gnucash/trunk/src/app-utils/app-utils.i
   gnucash/trunk/src/app-utils/guile-util.c
   gnucash/trunk/src/app-utils/guile-util.h
Log:
Add gnc_parse_time_to_timet, a concatenation of strptime and mktime.

This will be needed for the price quotes on systems that lack a guile
function `strptime'.


Modified: gnucash/trunk/src/app-utils/app-utils.i
===================================================================
--- gnucash/trunk/src/app-utils/app-utils.i	2007-04-28 16:04:06 UTC (rev 16015)
+++ gnucash/trunk/src/app-utils/app-utils.i	2007-04-28 19:13:43 UTC (rev 16016)
@@ -107,3 +107,5 @@
 
 gint gnc_process_get_fd(const Process *proc, const guint std_fd);
 void gnc_detach_process(Process *proc, const gboolean kill_it);
+
+time_t gnc_parse_time_to_timet(const gchar *s, const gchar *format);

Modified: gnucash/trunk/src/app-utils/guile-util.c
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.c	2007-04-28 16:04:06 UTC (rev 16015)
+++ gnucash/trunk/src/app-utils/guile-util.c	2007-04-28 19:13:43 UTC (rev 16016)
@@ -29,6 +29,9 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#ifndef HAVE_STRPTIME
+#    include "strptime.h"
+#endif
 
 #include "qof.h"
 #include "engine-helpers.h"
@@ -1292,3 +1295,17 @@
   else
     g_free (proc);
 }
+
+
+time_t
+gnc_parse_time_to_timet(const gchar *s, const gchar *format)
+{
+  struct tm tm;
+
+  g_return_val_if_fail(s && format, -1);
+
+  if (!strptime(s, format, &tm))
+    return -1;
+
+  return mktime(&tm);
+}

Modified: gnucash/trunk/src/app-utils/guile-util.h
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.h	2007-04-28 16:04:06 UTC (rev 16015)
+++ gnucash/trunk/src/app-utils/guile-util.h	2007-04-28 19:13:43 UTC (rev 16016)
@@ -140,3 +140,13 @@
 void gnc_detach_process(Process *proc, const gboolean kill_it);
 
 #endif
+
+/** Convert a time string to calendar time representation.  Combine strptime and
+ *  mktime into a single function to avoid the need to wrap struct tm *.
+ *
+ *  @param s String representation of time.
+ *
+ *  @param format Format specification.
+ *
+ *  @return The time in seconds since unix epoch, or -1 on error */
+time_t gnc_parse_time_to_timet(const gchar *s, const gchar *format);



More information about the gnucash-changes mailing list