[grisbi-cvs] grisbi/src utils_dates.c,1.61,1.62

Gunee guneemwelloeux at users.sourceforge.net
Tue Jan 19 17:06:10 CET 2010


Update of /cvsroot/grisbi/grisbi/src
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv11269

Modified Files:
	utils_dates.c 
Log Message:
MSVC: Getting short date format from OS for correct date parsing (bug 765)

Index: utils_dates.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/utils_dates.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- utils_dates.c	9 Jan 2010 20:57:38 -0000	1.61
+++ utils_dates.c	19 Jan 2010 16:06:08 -0000	1.62
@@ -22,9 +22,11 @@
 /* ************************************************************************** */
 
 #include "include.h"
-#ifndef _WIN32
-#	include <langinfo.h>
-#endif//_WIN32
+#ifdef _MSC_VER
+#include <winnls.h>
+#else
+#include <langinfo.h>
+#endif//_MSC_VER
 
 /*START_INCLUDE*/
 #include "utils_dates.h"
@@ -297,10 +299,10 @@
 GDate *gsb_parse_date_string ( const gchar *date_string )
 {
     GDate *date;
-    gchar * string, * format;
-    gchar ** tab_date;
+    gchar * string, * format, *sreturn;
+    gchar ** tab_date, ** tab_format;
     gchar date_tokens [ 4 ] = { 0, 0, 0, 0 };
-    int num_tokens = 0, num_fields = 0, i, j;
+    int num_tokens = 0, num_fields = 0, i, j, k;
 
     if ( !date_string
     ||
@@ -314,8 +316,26 @@
     g_strstrip ( string );
 
     /* Obtain date format tokens to compute order. */
-#ifdef _WIN32
-    format = "%d%m%Y";
+#ifdef _MSC_VER
+	sreturn = g_strnfill(81,'\0');
+	GetLocaleInfo(GetThreadLocale(), LOCALE_SSHORTDATE, sreturn, 80);
+	g_strcanon (sreturn, "dMy", '.');
+	tab_format = g_strsplit(sreturn, ".", 3);
+	g_free(sreturn);
+	format = "";
+	while (k < 3)
+	{
+		if(!strncmp(tab_format[k], "dd", 2) || !strncmp(tab_format[k], "d", 1))
+			format = g_strconcat(format, "%d", NULL);
+		else if(!strncmp(tab_format[k], "MM", 2) || !strncmp(tab_format[k], "M", 1))
+			format = g_strconcat(format, "%m", NULL);
+		else if(!strncmp(tab_format[k], "yyyy", 4))
+			format = g_strconcat(format, "%Y", NULL);
+		else if(!strncmp(tab_format[k], "yy", 2))
+			format = g_strconcat(format, "%y", NULL);
+		k++;
+	}
+	g_strfreev(tab_format);
 #else
     format = nl_langinfo ( D_FMT );
 #endif



More information about the cvs mailing list