mirror of https://github.com/djcb/mu.git
* make mu_msg_str_date[_s] take an strftime-like argument for the format;
update callers
This commit is contained in:
parent
55cd529bec
commit
ef4116efc2
|
@ -210,7 +210,7 @@ mug_msg_list_view_move_first (MugMsgListView *self)
|
||||||
{
|
{
|
||||||
GtkTreePath *path;
|
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 ();
|
path = gtk_tree_path_new_first ();
|
||||||
gtk_tree_view_set_cursor (GTK_TREE_VIEW(self), path,
|
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;
|
GtkTreeIter treeiter;
|
||||||
const gchar *date, *from, *subject, *path, *to;
|
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);
|
from = mu_msg_iter_get_from(iter);
|
||||||
to = mu_msg_iter_get_to (iter);
|
to = mu_msg_iter_get_to (iter);
|
||||||
subject = mu_msg_iter_get_subject (iter);
|
subject = mu_msg_iter_get_subject (iter);
|
||||||
|
|
|
@ -57,7 +57,7 @@ view_file (const gchar *path, const gchar *fields, size_t summary_len)
|
||||||
g_print ("Subject: %s\n", field);
|
g_print ("Subject: %s\n", field);
|
||||||
|
|
||||||
if ((date = mu_msg_get_date (msg)))
|
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) {
|
if (summary_len > 0) {
|
||||||
field = mu_msg_get_summary (msg, summary_len);
|
field = mu_msg_get_summary (msg, summary_len);
|
||||||
|
|
|
@ -50,22 +50,24 @@ mu_msg_str_normalize (const char *str, gboolean downcase)
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_str_date_s (time_t t)
|
mu_msg_str_date_s (const char* frm, time_t t)
|
||||||
{
|
{
|
||||||
struct tm *tmbuf;
|
struct tm *tmbuf;
|
||||||
static char buf[64];
|
static char buf[128];
|
||||||
|
|
||||||
|
g_return_val_if_fail (frm, NULL);
|
||||||
|
|
||||||
tmbuf = localtime(&t);
|
tmbuf = localtime(&t);
|
||||||
|
|
||||||
strftime (buf, sizeof(buf), "%x", tmbuf);
|
strftime (buf, sizeof(buf), frm, tmbuf);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,19 +31,21 @@ G_BEGIN_DECLS
|
||||||
/**
|
/**
|
||||||
* get a display string for a given time_t;
|
* get a display string for a given time_t;
|
||||||
* use the preferred date/time for the current locale
|
* 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,
|
* mu_msg_str_date_s returns a ptr to a static buffer,
|
||||||
* while mu_msg_str_date returns dynamically allocated
|
* while mu_msg_str_date returns dynamically allocated
|
||||||
* memory that must be freed after use.
|
* 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
|
* @param t the time as time_t
|
||||||
*
|
*
|
||||||
* @return a string representation of the time; see above
|
* @return a string representation of the time; see above for what to
|
||||||
* for what to do with it
|
* 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;
|
const char* mu_msg_str_date_s (const char* frm, time_t t) G_GNUC_CONST;
|
||||||
char* mu_msg_str_date (time_t t) G_GNUC_WARN_UNUSED_RESULT;
|
char* mu_msg_str_date (const char* frm, time_t t) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -64,11 +64,11 @@ display_field (MuMsgIter *iter, const MuMsgField* field)
|
||||||
|
|
||||||
case MU_MSG_FIELD_TYPE_TIME_T:
|
case MU_MSG_FIELD_TYPE_TIME_T:
|
||||||
val = mu_msg_iter_get_field_numeric (iter, field);
|
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:
|
case MU_MSG_FIELD_TYPE_BYTESIZE:
|
||||||
val = mu_msg_iter_get_field_numeric (iter, field);
|
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:
|
default:
|
||||||
g_return_val_if_reached (NULL);
|
g_return_val_if_reached (NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,13 +44,13 @@ test_mu_msg_str_date_01 (void)
|
||||||
strftime (buf, 64, "%x", tmbuf);
|
strftime (buf, 64, "%x", tmbuf);
|
||||||
|
|
||||||
/* $ date -ud@1234567890; Fri Feb 13 23:31:30 UTC 2009 */
|
/* $ 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 */
|
/* date -ud@987654321 Thu Apr 19 04:25:21 UTC 2001 */
|
||||||
some_time = 987654321;
|
some_time = 987654321;
|
||||||
tmbuf = localtime (&some_time);
|
tmbuf = localtime (&some_time);
|
||||||
strftime (buf, 64, "%x", tmbuf);
|
strftime (buf, 64, "%c", tmbuf);
|
||||||
tmp = mu_msg_str_date (some_time);
|
tmp = mu_msg_str_date ("%c", some_time);
|
||||||
|
|
||||||
g_assert_cmpstr (tmp, ==, buf);
|
g_assert_cmpstr (tmp, ==, buf);
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
|
|
Loading…
Reference in New Issue