* mu-str.[ch]: remove date-related stuff (now in mu-date.[ch])

This commit is contained in:
Dirk-Jan C. Binnema 2011-07-21 00:35:43 +03:00
parent fe245880fa
commit 58227acda4
2 changed files with 0 additions and 142 deletions

View File

@ -45,63 +45,6 @@
#include "mu-msg-flags.h"
#include "mu-msg-fields.h"
const char*
mu_str_date_s (const char* frm, time_t t)
{
struct tm *tmbuf;
static char buf[128];
static int is_utf8 = -1;
if (G_UNLIKELY(is_utf8 == -1))
is_utf8 = mu_util_locale_is_utf8 () ? 1 : 0;
g_return_val_if_fail (frm, NULL);
tmbuf = localtime(&t);
strftime (buf, sizeof(buf), frm, tmbuf);
if (!is_utf8) {
/* charset is _not_ utf8, so we need to convert it, so
* the date could contain locale-specific characters*/
gchar *conv;
GError *err;
err = NULL;
conv = g_locale_to_utf8 (buf, -1, NULL, NULL, &err);
if (err) {
g_warning ("conversion failed: %s", err->message);
g_error_free (err);
strcpy (buf, "<error>");
} else
strncpy (buf, conv, sizeof(buf));
g_free (conv);
}
return buf;
}
char*
mu_str_date (const char *frm, time_t t)
{
return g_strdup (mu_str_date_s(frm, t));
}
const char*
mu_str_display_date_s (time_t t)
{
time_t now;
static const time_t SECS_IN_DAY = 24 * 60 * 60;
now = time (NULL);
if (ABS(now - t) > SECS_IN_DAY)
return mu_str_date_s ("%x", t);
else
return mu_str_date_s ("%X", t);
}
const char*
mu_str_size_s (size_t s)
@ -309,41 +252,6 @@ is_xapian_prefix (const char *q, const char *colon)
return FALSE;
}
time_t
mu_str_date_parse_hdwmy (const char *nptr)
{
long int num;
char *endptr;
time_t now, delta;
time_t never = (time_t)-1;
g_return_val_if_fail (nptr, never);
num = strtol (nptr, &endptr, 10);
if (num <= 0 || num > 9999)
return never;
if (endptr == NULL || *endptr == '\0')
return never;
switch (endptr[0]) {
case 'h': /* hour */
delta = num * 60 * 60; break;
case 'd': /* day */
delta = num * 24 * 60 * 60; break;
case 'w': /* week */
delta = num * 7 * 24 * 60 * 60; break;
case 'm': /* month */
delta = num * 30 * 24 * 60 * 60; break;
case 'y': /* year */
delta = num * 365 * 24 * 60 * 60; break;
default:
return never;
}
now = time(NULL);
return delta <= now ? now - delta : never;
}
gint64
mu_str_size_parse_bkm (const char* str)

View File

@ -30,38 +30,6 @@
G_BEGIN_DECLS
/**
* get a string for a given time_t
*
* mu_str_date_s returns a ptr to a static buffer,
* while mu_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. 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_str_date_s (const char* frm, time_t t) G_GNUC_CONST;
char* mu_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_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_str_display_date_s (time_t t);
/**
* create a 'display contact' from an email header To/Cc/Bcc/From-type address
@ -193,24 +161,6 @@ char* mu_str_ascii_xapian_escape_in_place (char *query);
char* mu_str_ascii_xapian_escape (const char *query)
G_GNUC_WARN_UNUSED_RESULT;
/**
*
* parse strings like 1h, 3w, 2m to mean '1 hour before now', '3 weeks
* before now' and '2 * 30 days before now'
*
* the format is <n>(h|d|w|m|y), where <n> is an integer > 0, and
* h=hour, d=day, w=week, m=30 days, year=365 days. function returns
* *now* minus this value as time_t (UTC)
*
* if the number cannot be parsed, return (time_t)-1
*
* @param str a str
*
* @return the time_t of the point in time indicated by 'now' minus
* the value, or (time_t)-1 otherwise
*/
time_t mu_str_date_parse_hdwmy (const char* str);
/**