aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-time-utils.c
diff options
context:
space:
mode:
authorJP Rosevear <jpr@ximian.com>2002-08-22 23:39:41 +0800
committerJP Rosevear <jpr@src.gnome.org>2002-08-22 23:39:41 +0800
commit51e6a4e0ac56d46cf977d7f0e61f88e4c5134c22 (patch)
treec7dee70cb0bae987ae2b9b38b54f26ed546a6a00 /e-util/e-time-utils.c
parentfbe9e89258e82a7537b18c7b08858e550abcd24d (diff)
downloadgsoc2013-evolution-51e6a4e0ac56d46cf977d7f0e61f88e4c5134c22.tar.gz
gsoc2013-evolution-51e6a4e0ac56d46cf977d7f0e61f88e4c5134c22.tar.zst
gsoc2013-evolution-51e6a4e0ac56d46cf977d7f0e61f88e4c5134c22.zip
if the year was two digits, add the current century
2002-08-22 JP Rosevear <jpr@ximian.com> * e-time-utils.c (e_time_parse_date): if the year was two digits, add the current century svn path=/trunk/; revision=17833
Diffstat (limited to 'e-util/e-time-utils.c')
-rw-r--r--e-util/e-time-utils.c21
1 files changed, 20 insertions, 1 deletions
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;
}