Re-enable locale-based date parsing.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2686 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2000-08-22 05:48:43 +00:00
parent af7ac6c3a1
commit 0b293484b6
2 changed files with 36 additions and 22 deletions

View File

@ -27,6 +27,7 @@
#define _GNU_SOURCE
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -114,10 +115,10 @@ printDate (char * buff, int day, int month, int year)
{
struct tm tm_str;
tm_str.tm_mday = day;
tm_str.tm_mon = month - 1; /*tm_mon = 0 through 11 */
tm_str.tm_mon = month - 1; /* tm_mon = 0 through 11 */
tm_str.tm_year = year - 1900; /* this is what the standard
* says, it's not a Y2K thing
*/
* says, it's not a Y2K thing */
strftime(buff, MAX_DATE_LENGTH, "%x", &tm_str);
}
break;
@ -183,8 +184,8 @@ scanDate(const char *buff, int *day, int *month, int *year)
{
char *dupe, *tmp, *first_field, *second_field, *third_field;
int iday, imonth, iyear;
time_t secs;
struct tm *now;
time_t secs;
if (!buff) return;
@ -214,11 +215,10 @@ scanDate(const char *buff, int *day, int *month, int *year)
iyear = now->tm_year+1900;
/* get numeric values */
switch(dateFormat)
switch (dateFormat)
{
#if 0 /* strptime broken in glibc <= 2.1.2 */
case DATE_FORMAT_LOCALE:
if (buff[0] != 0)
if (buff[0] != '\0')
{
struct tm thetime;
@ -229,7 +229,6 @@ scanDate(const char *buff, int *day, int *month, int *year)
iyear = thetime.tm_year + 1900;
}
break;
#endif
case DATE_FORMAT_UK:
case DATE_FORMAT_CE:
if (first_field) iday = atoi (first_field);
@ -273,24 +272,39 @@ scanDate(const char *buff, int *day, int *month, int *year)
*/
char dateSeparator()
{
char separator;
static char locale_separator = '\0';
switch(dateFormat)
{
case DATE_FORMAT_CE:
separator='.';
break;
return '.';
case DATE_FORMAT_ISO:
separator='-';
break;
return '-';
case DATE_FORMAT_US:
case DATE_FORMAT_UK:
default:
separator='/';
break;
return '/';
case DATE_FORMAT_LOCALE:
if (locale_separator != '\0')
return locale_separator;
else
{ /* Make a guess */
char string[256];
struct tm *tm;
time_t secs;
char *s;
secs = time(NULL);
tm = localtime(&secs);
strftime(string, sizeof(string), "%x", tm);
for (s = string; s != '\0'; s++)
if (!isdigit(*s))
return (locale_separator = *s);
}
}
return separator;
return '\0';
}
/********************************************************************\

View File

@ -176,8 +176,8 @@ the account instead of opening a register." #f))
(list #(us "US" "US-style: mm/dd/yyyy")
#(uk "UK" "UK-style dd/mm/yyyy")
#(ce "Europe" "Continental Europe: dd.mm.yyyy")
#(iso "ISO" "ISO Standard: yyyy-mm-dd"))))
; #(locale "Locale" "Take from system locale"))))
#(iso "ISO" "ISO Standard: yyyy-mm-dd")
#(locale "Locale" "Default system locale format"))))
(gnc:register-configuration-option
(gnc:make-currency-option