From 0b293484b639f2f135eaff221b4bd18720c4ebd1 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Tue, 22 Aug 2000 05:48:43 +0000 Subject: [PATCH] Re-enable locale-based date parsing. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2686 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/date.c | 48 ++++++++++++++++++++++++++++++----------------- src/scm/prefs.scm | 10 +++++----- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/engine/date.c b/src/engine/date.c index 349e7797d1..d00b8673bc 100644 --- a/src/engine/date.c +++ b/src/engine/date.c @@ -27,6 +27,7 @@ #define _GNU_SOURCE +#include #include #include #include @@ -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; @@ -205,7 +206,7 @@ scanDate(const char *buff, int *day, int *month, int *year) } } } - + /* if any fields appear blank, use today's date */ time (&secs); now = localtime (&secs); @@ -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'; } /********************************************************************\ diff --git a/src/scm/prefs.scm b/src/scm/prefs.scm index ad6dc23999..b4981fd80f 100644 --- a/src/scm/prefs.scm +++ b/src/scm/prefs.scm @@ -173,11 +173,11 @@ the account instead of opening a register." #f)) (gnc:make-multichoice-option "International" "Date Format" "a" "Date Format Display" 'us - (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")))) + (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" "Default system locale format")))) (gnc:register-configuration-option (gnc:make-currency-option