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'.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16016 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Andreas Köhler 2007-04-28 19:13:43 +00:00
parent 433a0cd5e2
commit 94dc306411
3 changed files with 29 additions and 0 deletions

View File

@ -107,3 +107,5 @@ Process *gnc_spawn_process_async(GList *argl, const gboolean search_path);
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);

View File

@ -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 @@ gnc_detach_process (Process *proc, const gboolean kill_it)
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);
}

View File

@ -140,3 +140,13 @@ gint gnc_process_get_fd(const Process *proc, const gint std_fd);
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);