From 51e6a4e0ac56d46cf977d7f0e61f88e4c5134c22 Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Thu, 22 Aug 2002 15:39:41 +0000 Subject: if the year was two digits, add the current century 2002-08-22 JP Rosevear * e-time-utils.c (e_time_parse_date): if the year was two digits, add the current century svn path=/trunk/; revision=17833 --- e-util/e-time-utils.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'e-util/e-time-utils.c') diff --git a/e-util/e-time-utils.c b/e-util/e-time-utils.c index c07c280447..f91695f977 100644 --- a/e-util/e-time-utils.c +++ b/e-util/e-time-utils.c @@ -268,6 +268,9 @@ ETimeParseStatus e_time_parse_date (const char *value, struct tm *result) { const char *format[2]; + struct tm *today_tm; + time_t t; + ETimeParseStatus status; g_return_val_if_fail (value != NULL, E_TIME_PARSE_INVALID); g_return_val_if_fail (result != NULL, E_TIME_PARSE_INVALID); @@ -278,7 +281,23 @@ e_time_parse_date (const char *value, struct tm *result) /* This is the preferred date format for the locale. */ format[1] = _("%m/%d/%Y"); - return parse_with_strptime (value, result, format, sizeof (format) / sizeof (format[0])); + status = parse_with_strptime (value, result, format, sizeof (format) / sizeof (format[0])); + if (status == E_TIME_PARSE_OK) { + /* If a 2-digit year was used we use the current century. */ + if (result->tm_year < 0) { + t = time (NULL); + today_tm = localtime (&t); + + /* This should convert it into a value from 0 to 99. */ + result->tm_year += 1900; + + /* Now add on the century. */ + result->tm_year += today_tm->tm_year + - (today_tm->tm_year % 100); + } + } + + return status; } -- cgit