From f0a6d9725e8ef657f65f178faa264d0f47d8c2bd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 16 Jul 2010 15:02:02 -0500 Subject: Making the posibility of huge arrays testing length of month names and weekday names, and posibily both. --- src/indicator-datetime.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index adce0b2..ddb826c 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -677,9 +677,49 @@ build_timeval_array (GArray * timevals, gint mask) mytm.tm_yday = 363; g_array_append_val(timevals, mytm); - /* Sun 12/28/8888 12:00 */ - mytm.tm_hour = 12; - g_array_append_val(timevals, mytm); + if (mask & STRFTIME_MASK_AMPM) { + /* Sun 12/28/8888 12:00 */ + mytm.tm_hour = 12; + g_array_append_val(timevals, mytm); + } + + /* NOTE: Ignoring year 8888 should handle it */ + + if (mask & STRFTIME_MASK_MONTH) { + gint oldlen = timevals->len; + gint i, j; + for (i = 0; i < oldlen; i++) { + for (j = 0; j < 11; j++) { + struct tm localval = g_array_index(timevals, struct tm, i); + localval.tm_mon = j; + /* Not sure if I need to adjust yday & wday, hope not */ + g_array_append_val(timevals, localval); + } + } + } + + /* Doing these together as it seems like just slightly more + coverage on the numerical days, but worth it. */ + if (mask & (STRFTIME_MASK_WEEK | STRFTIME_MASK_DAY)) { + gint oldlen = timevals->len; + gint i, j; + for (i = 0; i < oldlen; i++) { + for (j = 22; j < 28; j++) { + struct tm localval = g_array_index(timevals, struct tm, i); + + gint diff = 28 - j; + + localval.tm_mday = j; + localval.tm_wday = localval.tm_wday - diff; + if (localval.tm_wday < 0) { + localval.tm_wday += 7; + } + localval.tm_yday = localval.tm_yday - diff; + + g_array_append_val(timevals, localval); + } + } + } return; } -- cgit v1.2.3