GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dialog-bi-import-helper.c
1 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #include "dialog-bi-import-helper.h"
27 #include <ctype.h>
28 #include <time.h>
29 #ifndef HAVE_STRPTIME
30 #include <strptime.h>
31 #endif
32 
34 gboolean text2bool( const gchar *text )
35 {
36  gboolean erg = FALSE;
37  gchar *temp;
38 
39  if (!text)
40  return erg;
41 
42  temp = g_strdup( text );
43  g_strstrip( temp );
44  if ((g_ascii_strncasecmp( temp, "y",1 ) == 0) || (g_ascii_strncasecmp( temp, "t",1 ) == 0) ||
45  (g_ascii_strcasecmp( temp, "1" ) == 0) || (g_ascii_strcasecmp( temp, "x" ) == 0))
46  erg = TRUE;
47  g_free( temp );
48  return erg;
49 }
50 
51 
53 // Try to make a valid tm using the user set date format. Return false if it fails.
54 gboolean
55 isDateValid(char * date_string)
56 {
57  char *tmp;
58  const gchar* date_format_string = qof_date_format_get_string (qof_date_format_get()); // Get the user set date format string
59 
60  struct tm time_struct;
61  memset(&time_struct, 0, sizeof(struct tm));
62 
63  tmp = strptime(date_string, date_format_string, &time_struct);
64  if (tmp == NULL) return FALSE;
65  return TRUE;
66 }
67 
69 GncAmountType text2disc_type( const gchar *text )
70 {
72  gchar *temp;
73 
74  if (!text)
75  return type;
76 
77  temp = g_strdup( text );
78  g_strstrip( temp );
79  if ((strlen(temp) > 0) && (g_ascii_strcasecmp( temp, "%" ) != 0))
80  type = GNC_AMT_TYPE_VALUE;
81  g_free( temp );
82  return type;
83 }
84 
86 GncDiscountHow text2disc_how( const gchar *text )
87 {
88  GncDiscountHow how = GNC_DISC_PRETAX;
89  gchar *temp;
90 
91  if (!text)
92  return how;
93 
94  temp = g_strdup( text );
95  g_strstrip( temp );
96  if (g_ascii_strcasecmp( temp, "=" ) == 0)
97  how = GNC_DISC_SAMETIME;
98  else if (g_ascii_strcasecmp( temp, ">" ) == 0)
99  how = GNC_DISC_POSTTAX;
100  g_free( temp );
101  return how;
102 }
const gchar * qof_date_format_get_string(QofDateFormat df)
QofDateFormat qof_date_format_get(void)
GncAmountType
Definition: gncTaxTable.h:93