* mu-msg-str.[ch]: add mu_msg_str_display_date_s, displays time for time with

24h, date otherwise
This commit is contained in:
Dirk-Jan C. Binnema 2010-11-07 18:24:48 +02:00
parent ab0ad61648
commit 93cf7856d1
2 changed files with 35 additions and 3 deletions

View File

@ -65,12 +65,31 @@ mu_msg_str_date_s (const char* frm, time_t t)
}
char*
mu_msg_str_date (const char* frm, time_t t)
mu_msg_str_date (const char *frm, time_t t)
{
return g_strdup (mu_msg_str_date_s(frm, t));
}
const char*
mu_msg_str_display_date_s (time_t t)
{
time_t now;
static const guint SECS_IN_DAY = 24 * 60 * 60;
now = time (NULL);
if (ABS(now - t) > SECS_IN_DAY)
return mu_msg_str_date_s ("%x", t);
else
return mu_msg_str_date_s ("%X", t);
}
const char*
mu_msg_str_size_s (size_t s)
{

View File

@ -29,8 +29,7 @@
G_BEGIN_DECLS
/**
* get a display string for a given time_t;
* use the preferred date/time for the current locale
* get a string for a given time_t
*
* mu_msg_str_date_s returns a ptr to a static buffer,
* while mu_msg_str_date returns dynamically allocated
@ -48,6 +47,20 @@ 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;
/**
* get a display string for a given time_t; if the given is less than
* 24h from the current time, we display the time, otherwise the date,
* using the preferred date/time for the current locale
*
* mu_msg_str_display_date_s returns a ptr to a static buffer,
*
* @param t the time as time_t
*
* @return a string representation of the time/date
*/
const char* mu_msg_str_display_date_s (time_t t);
/**
* get a display size for a given size_t; uses M for sizes >
* 1000*1000, k for smaller sizes. Note: this function use the