mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
parent
af7ac6c3a1
commit
0b293484b6
@ -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;
|
||||
|
||||
@ -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';
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user