diff --git a/src/engine/gnc-date.c b/src/engine/gnc-date.c index 7a21d54e4f..012ca1296d 100644 --- a/src/engine/gnc-date.c +++ b/src/engine/gnc-date.c @@ -692,7 +692,7 @@ qof_is_same_day (time_t ta, time_t tb) * month - will store month of the year as 1 ... 12 * year - will store the year (4-digit) * - * Return: nothing + * Return: TRUE if date appeared to be valid. * * Globals: global dateFormat value */ @@ -714,7 +714,7 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year, second_field = NULL; third_field = NULL; - /* use strtok to find delimiters */ + /* Use strtok to find delimiters */ if (tmp) { static char *delims = ".,-+/\\() "; @@ -727,7 +727,7 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year, } } - /* if any fields appear blank, use today's date */ + /* If any fields appear to be blank, use today's date */ time (&secs); now = localtime (&secs); iday = now->tm_mday; @@ -837,9 +837,13 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year, { int tmp = imonth; imonth = iday; iday = tmp; } + else + { + return FALSE; + } } - /* if the year entered is smaller than 100, assume we mean the current + /* If the year entered is smaller than 100, assume we mean the current century (and are not revising some roman emperor's books) */ if (iyear < 100) iyear += ((int) ((now->tm_year+1950-iyear)/100)) * 100; @@ -850,10 +854,22 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year, return(TRUE); } -void +gboolean qof_scan_date (const char *buff, int *day, int *month, int *year) { - qof_scan_date_internal(buff, day, month, year, dateFormat); + return qof_scan_date_internal(buff, day, month, year, dateFormat); +} + +gboolean +qof_scan_date_secs (const char *buff, time_t *secs) +{ + gboolean rc; + int day, month, year; + + rc = qof_scan_date_internal(buff, &day, &month, &year, dateFormat); + if (secs) *secs = xaccDMYToSec (day, month, year); + + return rc; } /** diff --git a/src/engine/gnc-date.h b/src/engine/gnc-date.h index 5bdfac0bc8..6dc9e23cdd 100644 --- a/src/engine/gnc-date.h +++ b/src/engine/gnc-date.h @@ -345,11 +345,14 @@ char * xaccDateUtilGetStamp (time_t thyme); * month - will store month of the year as 1 ... 12 * year - will store the year (4-digit) * - * Return: nothing + * Return: TRUE if the string seemed to be a valid date; else FALSE. * - * Globals: global dateFormat value + * Globals: uses global dateFormat value to assist in parsing. */ -void qof_scan_date (const char *buff, int *day, int *month, int *year); +gboolean qof_scan_date (const char *buff, int *day, int *month, int *year); + +/** as above, but returns seconds */ +gboolean qof_scan_date_secs (const char *buff, time_t *secs); /** @name Date Start/End Adjustment routines