diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2007-12-03 21:19:39 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2007-12-03 21:19:39 +0800 |
commit | 796e7ca63b134fca7767d1b009aa973c03fd46a6 (patch) | |
tree | 1c43762c65bc236403e02c5d5f0ffd531ada3d80 /e-util | |
parent | 0432e0fb2709cf09a898a8c9cf914ed7e81e88b1 (diff) | |
download | gsoc2013-evolution-796e7ca63b134fca7767d1b009aa973c03fd46a6.tar gsoc2013-evolution-796e7ca63b134fca7767d1b009aa973c03fd46a6.tar.gz gsoc2013-evolution-796e7ca63b134fca7767d1b009aa973c03fd46a6.tar.bz2 gsoc2013-evolution-796e7ca63b134fca7767d1b009aa973c03fd46a6.tar.lz gsoc2013-evolution-796e7ca63b134fca7767d1b009aa973c03fd46a6.tar.xz gsoc2013-evolution-796e7ca63b134fca7767d1b009aa973c03fd46a6.tar.zst gsoc2013-evolution-796e7ca63b134fca7767d1b009aa973c03fd46a6.zip |
** Fixes bug #392747
2007-12-03 Matthew Barnes <mbarnes@redhat.com>
** Fixes bug #392747
* e-util/e-utils.c (e_get_month_name), (e_get_weekday_name):
New functions cache localized month and weekday names (respectively)
for easier retrieval than resorting to strftime().
* a11y/widgets/ea-calendar-item.c (ea_calendar_item_get_column_label):
Get the column label via e_get_weekday_name().
* calendar/gui/weekday-picker.c (get_day_text):
Convert the day_index to GDateWeekday and call e_get_weekday_name().
* widgets/misc/e-calendar-item.h (struct _ECalendarItem):
* widgets/misc/e-calendar-item.c (e_calendar_item_init),
(e_calendar_item_draw):
Lose the local weekday name cache and just call e_get_weekday_name().
svn path=/trunk/; revision=34627
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/ChangeLog | 8 | ||||
-rw-r--r-- | e-util/e-util.c | 94 | ||||
-rw-r--r-- | e-util/e-util.h | 4 |
3 files changed, 106 insertions, 0 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index d44416e18e..0c5834debc 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,11 @@ +2007-12-03 Matthew Barnes <mbarnes@redhat.com> + + ** Fixes part of bug #392747 + + * e-utils.c (e_get_month_name), (e_get_weekday_name): + New functions cache localized month and weekday names (respectively) + for easier retrieval than resorting to strftime(). + 2007-11-13 Ondrej Jirman <megous@megous.com> ** Fix for bug #494320 diff --git a/e-util/e-util.c b/e-util/e-util.c index 2515e78eb2..625c617a8b 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -547,6 +547,100 @@ e_utf8_strftime_fix_am_pm (gchar *str, gsize max, const gchar *fmt, } /** + * e_get_month_name: + * @month: month index + * @abbreviated: if %TRUE, abbreviate the month name + * + * Returns the localized name for @month. If @abbreviated is %TRUE, + * returns the locale's abbreviated month name. + * + * Returns: localized month name + **/ +const gchar * +e_get_month_name (GDateMonth month, + gboolean abbreviated) +{ + /* Make the indices correspond to the enum values. */ + static const gchar *abbr_names[G_DATE_DECEMBER + 1]; + static const gchar *full_names[G_DATE_DECEMBER + 1]; + static gboolean first_time = TRUE; + + g_return_val_if_fail (month >= G_DATE_JANUARY, NULL); + g_return_val_if_fail (month <= G_DATE_DECEMBER, NULL); + + if (G_UNLIKELY (first_time)) { + gchar buffer[256]; + GDateMonth ii; + GDate date; + + memset (abbr_names, 0, sizeof (abbr_names)); + memset (full_names, 0, sizeof (full_names)); + + /* First Julian day was in January. */ + g_date_set_julian (&date, 1); + + for (ii = G_DATE_JANUARY; ii <= G_DATE_DECEMBER; ii++) { + g_date_strftime (buffer, sizeof (buffer), "%b", &date); + abbr_names[ii] = g_intern_string (buffer); + g_date_strftime (buffer, sizeof (buffer), "%B", &date); + full_names[ii] = g_intern_string (buffer); + g_date_add_months (&date, 1); + } + + first_time = FALSE; + } + + return abbreviated ? abbr_names[month] : full_names[month]; +} + +/** + * e_get_weekday_name: + * @weekday: weekday index + * @abbreviated: if %TRUE, abbreviate the weekday name + * + * Returns the localized name for @weekday. If @abbreviated is %TRUE, + * returns the locale's abbreviated weekday name. + * + * Returns: localized weekday name + **/ +const gchar * +e_get_weekday_name (GDateWeekday weekday, + gboolean abbreviated) +{ + /* Make the indices correspond to the enum values. */ + static const gchar *abbr_names[G_DATE_SUNDAY + 1]; + static const gchar *full_names[G_DATE_SUNDAY + 1]; + static gboolean first_time = TRUE; + + g_return_val_if_fail (weekday >= G_DATE_MONDAY, NULL); + g_return_val_if_fail (weekday <= G_DATE_SUNDAY, NULL); + + if (G_UNLIKELY (first_time)) { + gchar buffer[256]; + GDateWeekday ii; + GDate date; + + memset (abbr_names, 0, sizeof (abbr_names)); + memset (full_names, 0, sizeof (full_names)); + + /* First Julian day was a Monday. */ + g_date_set_julian (&date, 1); + + for (ii = G_DATE_MONDAY; ii <= G_DATE_SUNDAY; ii++) { + g_date_strftime (buffer, sizeof (buffer), "%a", &date); + abbr_names[ii] = g_intern_string (buffer); + g_date_strftime (buffer, sizeof (buffer), "%A", &date); + full_names[ii] = g_intern_string (buffer); + g_date_add_days (&date, 1); + } + + first_time = FALSE; + } + + return abbreviated ? abbr_names[weekday] : full_names[weekday]; +} + +/** * e_flexible_strtod: * @nptr: the string to convert to a numeric value. * @endptr: if non-NULL, it returns the character after diff --git a/e-util/e-util.h b/e-util/e-util.h index c2983f454f..e3774c5852 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -82,6 +82,10 @@ gsize e_utf8_strftime_fix_am_pm (gchar *str, gsize max, const gchar *fmt, const struct tm *tm); +const gchar * e_get_month_name (GDateMonth month, + gboolean abbreviated); +const gchar * e_get_weekday_name (GDateWeekday weekday, + gboolean abbreviated); /* String to/from double conversion functions */ gdouble e_flexible_strtod (const gchar *nptr, |