diff --git a/src/engine/date.c b/src/engine/date.c index 8b2efaa2f5..52f1331e72 100644 --- a/src/engine/date.c +++ b/src/engine/date.c @@ -330,9 +330,10 @@ char dateSeparator () /* hack alert -- this routine returns incorrect values for * dates before 1970 */ -Timespec -gnc_iso8601_to_timespec(const char *str) +static Timespec +gnc_iso8601_to_timespec(const char *str, int do_localtime) { + char buf[4]; Timespec ts; struct tm stm; long int nsec =0; @@ -355,16 +356,49 @@ gnc_iso8601_to_timespec(const char *str) stm.tm_sec = atoi (str); /* the decimal point, optionally present ... */ - /* hack alert -- we should count number of decimal places, */ + /* hack alert -- this algo breaks if more than 9 decimal places present */ if (strchr (str, '.')) { + int decimals, i, multiplier=1000000000; str = strchr (str, '.') +1; - nsec = atoi(str) *10000000; + decimals = strcspn (str, "+- "); + for (i=0; itz_hour) { cyn = '-'; tz_hour = -tz_hour; } + cyn = '-'; + if (0>tz_hour) { cyn = '+'; tz_hour = -tz_hour; } len = sprintf (buff, "%4d-%02d-%02d %02d:%02d:%02d.%06ld %c%02d%02d", parsed.tm_year+1900, parsed.tm_mon+1, parsed.tm_mday, diff --git a/src/engine/date.h b/src/engine/date.h index 76837acbcf..68fc0abe49 100644 --- a/src/engine/date.h +++ b/src/engine/date.h @@ -148,10 +148,12 @@ Timespec gnc_dmy2timespec (int day, int month, int year); /* Same as gnc_dmy2timespec, but last second of the day */ Timespec gnc_dmy2timespec_end (int day, int month, int year); -/* The gnc_iso8601_to_timespec() routine converts an ISO-8601 style +/* The gnc_iso8601_to_timespec_xxx() routines converts an ISO-8601 style * date/time string to Timespec. * For example: 1998-07-17 11:00:00.68-05 * is 680 milliseconds after 11 o'clock, central daylight time + * The _gmt() routine returns the time in gmt. The _local() routine + * returns the local time. * * The gnc_timespec_to_iso8601_buff() routine prints a Timespec * as an ISO-8601 style string. The buffer must be long enough @@ -159,7 +161,8 @@ Timespec gnc_dmy2timespec_end (int day, int month, int year); * routine returns a pointer to the null terminator (and can * thus be used in the 'stpcpy' metaphor of string concatenation). */ -Timespec gnc_iso8601_to_timespec(const char *); +Timespec gnc_iso8601_to_timespec_local(const char *); +Timespec gnc_iso8601_to_timespec_gmt(const char *); char * gnc_timespec_to_iso8601_buff (Timespec ts, char * buff); #endif /* __XACC_DATE_H__ */