Combine two copies of "dow abbrev[iation]" code.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15837 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Joshua Sled
2007-04-06 02:22:29 +00:00
parent f7206b1fd1
commit 897633f01b
4 changed files with 36 additions and 37 deletions

View File

@@ -1514,5 +1514,15 @@ gnc_timet_get_today_end (void)
return mktime(&tm);
}
/********************** END OF FILE *********************************\
\********************************************************************/
void
gnc_dow_abbrev(gchar *buf, int buf_len, int dow)
{
struct tm my_tm;
int i;
memset(buf, 0, buf_len);
memset(&my_tm, 0, sizeof(struct tm));
my_tm.tm_wday = dow;
i = qof_strftime(buf, buf_len - 1, "%a", &my_tm);
buf[i] = 0;
}

View File

@@ -564,6 +564,14 @@ time_t gnc_timet_get_today_end(void);
* @note The caller owns this buffer and must free it when done. */
char * xaccDateUtilGetStampNow (void);
#define MIN_BUF_LEN 10
/**
* Localized DOW abbreviation.
* @param buf_len at least MIN_BUF_LEN
* @param dow struct tm semantics: 0=sunday .. 6=saturday
**/
void gnc_dow_abbrev(gchar *buf, int buf_len, int dow);
//@}
//@}
#endif /* GNC_DATE_H */

View File

@@ -393,24 +393,6 @@ recurrenceListIsWeeklyMultiple(GList *recurrences)
return TRUE;
}
/**
* Localized DOW abbrev.
* @fixme - ripped from gnc-dense-cal.c; there can be only one. :p
* @param dow struct tm semantics: 0=sunday .. 6=saturday
**/
static void
_dow_abbrev(gchar *buf, int buf_len, int dow)
{
struct tm my_tm;
int i;
memset(buf, 0, buf_len);
memset(&my_tm, 0, sizeof(struct tm));
my_tm.tm_wday = dow;
i = qof_strftime(buf, buf_len - 1, "%a", &my_tm);
buf[i] = 0;
}
static void
_weekly_list_to_compact_string(GList *rs, GString *buf)
{
@@ -428,7 +410,9 @@ _weekly_list_to_compact_string(GList *rs, GString *buf)
continue;
}
dow_present_bits |= (1 << (dow % 7));
// broken, @fixme.
// there's not necessarily a single multiplier, but for all intents
// and purposes this will be fine.
multiplier = recurrenceGetMultiplier(r);
}
g_string_printf(buf, _("Weekly"));
@@ -445,7 +429,7 @@ _weekly_list_to_compact_string(GList *rs, GString *buf)
if ((dow_present_bits & (1 << dow_idx)) != 0)
{
gchar dbuf[10];
_dow_abbrev(dbuf, 10, dow_idx);
gnc_dow_abbrev(dbuf, 9, dow_idx);
g_string_append_printf(buf, "%c", dbuf[0]);
}
else
@@ -462,9 +446,9 @@ _monthly_append_when(Recurrence *r, GString *buf)
if (recurrenceGetPeriodType(r) == PERIOD_LAST_WEEKDAY)
{
gint abbrev_day_name_bufsize = 10;
gchar day_name_buf[abbrev_day_name_bufsize];
gchar day_name_buf[abbrev_day_name_bufsize+1];
_dow_abbrev(day_name_buf, abbrev_day_name_bufsize, g_date_get_weekday(&date) % 7);
gnc_dow_abbrev(day_name_buf, abbrev_day_name_bufsize, g_date_get_weekday(&date) % 7);
/* translators: %s is an already-localized form of the day of the week. */
g_string_append_printf(buf, _("last %s"), day_name_buf);

View File

@@ -145,10 +145,12 @@ static void gdc_remove_markings(GncDenseCal *cal);
static GObject *parent_class = NULL;
#define MONTH_NAME_BUFSIZE 5
/* Takes the number of months since January, in the range 0 to
* 11. Returns the abbreviated month name according to the current
* locale.*/
static const gchar *month_name(int mon)
static const gchar*
month_name(int mon)
{
static gchar buf[MONTH_NAME_BUFSIZE];
GDate date;
@@ -165,21 +167,15 @@ static const gchar *month_name(int mon)
return buf;
}
/* Takes the number of days since Sunday, in the range 0 to 6. Returns
* the abbreviated weekday name according to the current locale. */
static const gchar *day_label(int wday)
static void
day_label(gchar *buf, int buf_len, int dow)
{
static gchar buf[MONTH_NAME_BUFSIZE];
struct tm my_tm;
int i;
memset(buf, 0, MONTH_NAME_BUFSIZE);
memset(&my_tm, 0, sizeof(struct tm));
my_tm.tm_wday = wday;
i = qof_strftime (buf, MONTH_NAME_BUFSIZE-1, "%a", &my_tm);
gnc_dow_abbrev(buf, buf_len, dow);
/* Wild hack to use only the first two letters */
buf[2]='\0';
return buf;
}
GType
@@ -992,9 +988,10 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
{
int day_label_width;
gint label_x_offset, label_y_offset;
const gchar *day_label_str;
gint day_label_str_len = 3;
gchar day_label_str[day_label_str_len+1];
day_label_str = day_label((j + dcal->week_starts_monday) % 7);
day_label(day_label_str, day_label_str_len, (j + dcal->week_starts_monday) % 7);
pango_layout_set_text(layout, day_label_str, -1);
pango_layout_get_pixel_size(layout, &day_label_width, NULL);
label_x_offset = x