* make mu_msg_str_date[_s] take an strftime-like argument for the format;

update callers
This commit is contained in:
Dirk-Jan C. Binnema 2010-11-03 07:43:46 +02:00
parent 55cd529bec
commit ef4116efc2
6 changed files with 22 additions and 18 deletions

View File

@ -210,7 +210,7 @@ mug_msg_list_view_move_first (MugMsgListView *self)
{
GtkTreePath *path;
g_return_val_if_fail (MUG_IS_MSG_LIST_VIEW(self), FALSE);
g_return_if_fail (MUG_IS_MSG_LIST_VIEW(self));
path = gtk_tree_path_new_first ();
gtk_tree_view_set_cursor (GTK_TREE_VIEW(self), path,
@ -303,7 +303,7 @@ update_model (GtkListStore *store, const char *xpath, const char *query)
GtkTreeIter treeiter;
const gchar *date, *from, *subject, *path, *to;
date = mu_msg_str_date_s (mu_msg_iter_get_date (iter));
date = mu_msg_str_date_s ("%x", mu_msg_iter_get_date (iter));
from = mu_msg_iter_get_from(iter);
to = mu_msg_iter_get_to (iter);
subject = mu_msg_iter_get_subject (iter);

View File

@ -57,7 +57,7 @@ view_file (const gchar *path, const gchar *fields, size_t summary_len)
g_print ("Subject: %s\n", field);
if ((date = mu_msg_get_date (msg)))
g_print ("Date: %s\n", mu_msg_str_date_s (date));
g_print ("Date: %s\n", mu_msg_str_date_s ("%c", date));
if (summary_len > 0) {
field = mu_msg_get_summary (msg, summary_len);

View File

@ -50,22 +50,24 @@ mu_msg_str_normalize (const char *str, gboolean downcase)
const char*
mu_msg_str_date_s (time_t t)
mu_msg_str_date_s (const char* frm, time_t t)
{
struct tm *tmbuf;
static char buf[64];
static char buf[128];
g_return_val_if_fail (frm, NULL);
tmbuf = localtime(&t);
strftime (buf, sizeof(buf), "%x", tmbuf);
strftime (buf, sizeof(buf), frm, tmbuf);
return buf;
}
char*
mu_msg_str_date (time_t t)
mu_msg_str_date (const char* frm, time_t t)
{
return g_strdup (mu_msg_str_date_s(t));
return g_strdup (mu_msg_str_date_s(frm, t));
}

View File

@ -31,19 +31,21 @@ G_BEGIN_DECLS
/**
* get a display string for a given time_t;
* use the preferred date/time for the current locale
* (ie., '%c' in strftime).
*
* mu_msg_str_date_s returns a ptr to a static buffer,
* while mu_msg_str_date returns dynamically allocated
* memory that must be freed after use.
*
* @param frm the format of the string (in strftime(3) format)
* @param t the time as time_t
*
* @return a string representation of the time; see above
* for what to do with it
* @return a string representation of the time; see above for what to
* do with it. Lenght is max. 128 bytes, inc. the ending \0. if the
* format is too long, the value will be truncated. in practice this
* should not happen.
*/
const char* mu_msg_str_date_s (time_t t) G_GNUC_CONST;
char* mu_msg_str_date (time_t t) G_GNUC_WARN_UNUSED_RESULT;
const char* mu_msg_str_date_s (const char* frm, time_t t) G_GNUC_CONST;
char* mu_msg_str_date (const char* frm, time_t t) G_GNUC_WARN_UNUSED_RESULT;
/**

View File

@ -64,11 +64,11 @@ display_field (MuMsgIter *iter, const MuMsgField* field)
case MU_MSG_FIELD_TYPE_TIME_T:
val = mu_msg_iter_get_field_numeric (iter, field);
return mu_msg_str_date_s ((time_t)val);
return mu_msg_str_date_s ("%c", (time_t)val);
case MU_MSG_FIELD_TYPE_BYTESIZE:
val = mu_msg_iter_get_field_numeric (iter, field);
return mu_msg_str_size_s ((time_t)val);
return mu_msg_str_size_s ((unsigned)val);
default:
g_return_val_if_reached (NULL);
}

View File

@ -44,13 +44,13 @@ test_mu_msg_str_date_01 (void)
strftime (buf, 64, "%x", tmbuf);
/* $ date -ud@1234567890; Fri Feb 13 23:31:30 UTC 2009 */
g_assert_cmpstr (mu_msg_str_date_s (some_time), ==, buf);
g_assert_cmpstr (mu_msg_str_date_s ("%x", some_time), ==, buf);
/* date -ud@987654321 Thu Apr 19 04:25:21 UTC 2001 */
some_time = 987654321;
tmbuf = localtime (&some_time);
strftime (buf, 64, "%x", tmbuf);
tmp = mu_msg_str_date (some_time);
strftime (buf, 64, "%c", tmbuf);
tmp = mu_msg_str_date ("%c", some_time);
g_assert_cmpstr (tmp, ==, buf);
g_free (tmp);