aboutsummaryrefslogtreecommitdiffstats
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
parentfbe9e89258e82a7537b18c7b08858e550abcd24d (diff)
downloadgsoc2013-evolution-51e6a4e0ac56d46cf977d7f0e61f88e4c5134c22.tar
gsoc2013-evolution-51e6a4e0ac56d46cf977d7f0e61f88e4c5134c22.tar.gz
gsoc2013-evolution-51e6a4e0ac56d46cf977d7f0e61f88e4c5134c22.tar.bz2
gsoc2013-evolution-51e6a4e0ac56d46cf977d7f0e61f88e4c5134c22.tar.lz
gsoc2013-evolution-51e6a4e0ac56d46cf977d7f0e61f88e4c5134c22.tar.xz
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
-rw-r--r--e-util/ChangeLog5
-rw-r--r--e-util/e-time-utils.c21
2 files changed, 25 insertions, 1 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 26e78fb47f..bab1aff790 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,8 @@
+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
+
2002-08-16 Rodrigo Moya <rodrigo@ximian.com>
* e-config-listener.[ch]: new class for config database access and
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;
}