diff options
author | Ted Gould <ted@gould.cx> | 2010-07-16 15:02:02 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-07-16 15:02:02 -0500 |
commit | f0a6d9725e8ef657f65f178faa264d0f47d8c2bd (patch) | |
tree | b1225b39a146e0a33d9c2b7407b2963fb0bc81e4 /src | |
parent | 621f199bb54a6da98a33885b383589cdd6187766 (diff) | |
download | ayatana-indicator-datetime-f0a6d9725e8ef657f65f178faa264d0f47d8c2bd.tar.gz ayatana-indicator-datetime-f0a6d9725e8ef657f65f178faa264d0f47d8c2bd.tar.bz2 ayatana-indicator-datetime-f0a6d9725e8ef657f65f178faa264d0f47d8c2bd.zip |
Making the posibility of huge arrays testing length of month names and weekday names, and posibily both.
Diffstat (limited to 'src')
-rw-r--r-- | src/indicator-datetime.c | 46 |
1 files changed, 43 insertions, 3 deletions
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; } |