Skip to content

Commit

Permalink
rename date functions
Browse files Browse the repository at this point in the history
  • Loading branch information
flatcap committed Nov 16, 2017
1 parent a7db5c5 commit 35a328e
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ int mutt_copy_message_fp(FILE *fpout, FILE *fpin, struct Header *hdr, int flags,
LOFF_T new_length = body->length;
char date[SHORT_STRING];

mutt_make_date(date, sizeof(date));
mutt_date_make_date(date, sizeof(date));
int dlen = mutt_strlen(date);
if (dlen == 0)
return -1;
Expand Down
10 changes: 5 additions & 5 deletions from.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)

mutt_debug(3, "\nis_from(): parsing: %s\n", s);

if (!is_day_name(s))
if (!mutt_date_is_day_name(s))
{
const char *p = NULL;
size_t len;
Expand Down Expand Up @@ -102,7 +102,7 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
if (!*s)
return 0;

if (!is_day_name(s))
if (!mutt_date_is_day_name(s))
{
mutt_debug(1, "is_from(): expected weekday, got: %s\n", s);
return 0;
Expand All @@ -117,15 +117,15 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
* this could happen when receiving mail from a local user whose login name
* is the same as a three-letter abbreviation of the day of the week.
*/
if (is_day_name(s))
if (mutt_date_is_day_name(s))
{
s = next_word(s);
if (!*s)
return 0;
}

/* now we should be on the month. */
tm.tm_mon = mutt_check_month(s);
tm.tm_mon = mutt_date_check_month(s);
if (tm.tm_mon < 0)
return 0;

Expand Down Expand Up @@ -191,6 +191,6 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
tm.tm_isdst = -1;

if (tp)
*tp = mutt_mktime(&tm, 0);
*tp = mutt_date_make_time(&tm, 0);
return 1;
}
2 changes: 1 addition & 1 deletion handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ static int external_body_handler(struct Body *b, struct State *s)

expiration = mutt_get_parameter("expiration", b->parameter);
if (expiration)
expire = mutt_parse_date(expiration, NULL);
expire = mutt_date_parse_date(expiration, NULL);
else
expire = -1;

Expand Down
4 changes: 2 additions & 2 deletions imap/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ static int msg_parse_fetch(struct ImapHeader *h, char *s)
return -1;
s++; /* skip past the trailing " */
*ptmp = '\0';
h->received = imap_parse_date(tmp);
h->received = mutt_date_parse_imap(tmp);
}
else if (mutt_strncasecmp("RFC822.SIZE", s, 11) == 0)
{
Expand Down Expand Up @@ -1294,7 +1294,7 @@ int imap_append_message(struct Context *ctx, struct Message *msg)
MUTT_PROGRESS_SIZE, NetInc, len);

imap_munge_mbox_name(idata, mbox, sizeof(mbox), mailbox);
imap_make_date(internaldate, sizeof(internaldate), msg->received);
mutt_date_make_imap(internaldate, sizeof(internaldate), msg->received);

imap_flags[0] = imap_flags[1] = 0;
if (msg->flags.read)
Expand Down
4 changes: 2 additions & 2 deletions mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static int mmdf_parse_mailbox(struct Context *ctx)
}
}
else
hdr->received = t - mutt_local_tz(t);
hdr->received = t - mutt_date_local_tz(t);

hdr->env = mutt_read_rfc822_header(ctx->fp, hdr, 0, 0);

Expand Down Expand Up @@ -313,7 +313,7 @@ static int mbox_parse_mailbox(struct Context *ctx)
mx_alloc_memory(ctx);

curhdr = ctx->hdrs[ctx->msgcount] = mutt_new_header();
curhdr->received = t - mutt_local_tz(t);
curhdr->received = t - mutt_date_local_tz(t);
curhdr->offset = loc;
curhdr->index = ctx->msgcount;

Expand Down
70 changes: 35 additions & 35 deletions mutt/date.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
* | #TimeZones | Lookup table of Time Zones
* | #Weekdays | Day of the week (abbreviated)
*
* | Function | Description
* | :-------------------- | :--------------------------------------------------
* | imap_make_date() | Format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz
* | imap_parse_date() | Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz
* | is_day_name() | Is the string a valid day name
* | mutt_check_month() | Is the string a valid month name
* | mutt_local_tz() | Calculate the local timezone in seconds east of UTC
* | mutt_make_date() | Write a date in RFC822 format to a buffer
* | mutt_mktime() | Convert `struct tm` to `time_t`
* | mutt_normalize_time() | Fix the contents of a struct tm
* | mutt_parse_date() | Parse a date string in RFC822 format
* | Function | Description
* | :------------------------- | :--------------------------------------------------
* | mutt_date_check_month() | Is the string a valid month name
* | mutt_date_is_day_name() | Is the string a valid day name
* | mutt_date_local_tz() | Calculate the local timezone in seconds east of UTC
* | mutt_date_make_date() | Write a date in RFC822 format to a buffer
* | mutt_date_make_imap() | Format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz
* | mutt_date_make_time() | Convert `struct tm` to `time_t`
* | mutt_date_normalize_time() | Fix the contents of a struct tm
* | mutt_date_parse_date() | Parse a date string in RFC822 format
* | mutt_date_parse_imap() | Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz
*/

#include "config.h"
Expand Down Expand Up @@ -211,14 +211,14 @@ static const char *uncomment_timezone(char *buf, size_t buflen, const char *tz)
}

/**
* mutt_local_tz - Calculate the local timezone in seconds east of UTC
* mutt_date_local_tz - Calculate the local timezone in seconds east of UTC
* @param t Time to examine
* @retval num Seconds east of UTC
*
* Returns the local timezone in seconds east of UTC for the time t,
* or for the current time if t is zero.
*/
time_t mutt_local_tz(time_t t)
time_t mutt_date_local_tz(time_t t)
{
/* Check we haven't overflowed the time (on 32-bit arches) */
if ((t == TIME_T_MAX) || (t == TIME_T_MIN))
Expand All @@ -237,15 +237,15 @@ time_t mutt_local_tz(time_t t)
}

/**
* mutt_mktime - Convert `struct tm` to `time_t`
* mutt_date_make_time - Convert `struct tm` to `time_t`
* @param t Time to convert
* @param local Should the local timezone be considered
* @retval num Time in Unix format
*
* Convert a struct tm to time_t, but don't take the local timezone into
* account unless ``local'' is nonzero
*/
time_t mutt_mktime(struct tm *t, int local)
time_t mutt_date_make_time(struct tm *t, int local)
{
time_t g;

Expand Down Expand Up @@ -301,15 +301,15 @@ time_t mutt_mktime(struct tm *t, int local)
}

/**
* mutt_normalize_time - Fix the contents of a struct tm
* mutt_date_normalize_time - Fix the contents of a struct tm
* @param tm Time to correct
*
* If values have been added/subtracted from a struct tm, it can lead to
* invalid dates, e.g. Adding 10 days to the 25th of a month.
*
* This function will correct any over/under-flow.
*/
void mutt_normalize_time(struct tm *tm)
void mutt_date_normalize_time(struct tm *tm)
{
static const char DaysPerMonth[12] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
Expand Down Expand Up @@ -382,16 +382,16 @@ void mutt_normalize_time(struct tm *tm)
}

/**
* mutt_make_date - Write a date in RFC822 format to a buffer
* mutt_date_make_date - Write a date in RFC822 format to a buffer
* @param buf Buffer for result
* @param buflen Length of buffer
* @retval ptr Buffer containing result
*/
char *mutt_make_date(char *buf, size_t buflen)
char *mutt_date_make_date(char *buf, size_t buflen)
{
time_t t = time(NULL);
struct tm *l = localtime(&t);
time_t tz = mutt_local_tz(t);
time_t tz = mutt_date_local_tz(t);

tz /= 60;

Expand All @@ -402,15 +402,15 @@ char *mutt_make_date(char *buf, size_t buflen)
}

/**
* mutt_check_month - Is the string a valid month name
* mutt_date_check_month - Is the string a valid month name
* @param s String to check
* @retval num Index into Months array (0-based)
* @retval -1 Error
*
* @note Only the first three characters are checked
* @note The comparison is case insensitive
*/
int mutt_check_month(const char *s)
int mutt_date_check_month(const char *s)
{
for (int i = 0; i < 12; i++)
if (mutt_strncasecmp(s, Months[i], 3) == 0)
Expand All @@ -420,14 +420,14 @@ int mutt_check_month(const char *s)
}

/**
* is_day_name - Is the string a valid day name
* mutt_date_is_day_name - Is the string a valid day name
* @param s String to check
* @retval boolean
*
* @note Only the first three characters are checked
* @note The comparison is case insensitive
*/
bool is_day_name(const char *s)
bool mutt_date_is_day_name(const char *s)
{
if ((strlen(s) < 3) || !*(s + 3) || !ISSPACE(*(s + 3)))
return false;
Expand All @@ -440,7 +440,7 @@ bool is_day_name(const char *s)
}

/**
* mutt_parse_date - Parse a date string in RFC822 format
* mutt_date_parse_date - Parse a date string in RFC822 format
* @param[in] s String to parse
* @param[out] tz_out Pointer to timezone (optional)
* @retval num Unix time in seconds
Expand All @@ -450,7 +450,7 @@ bool is_day_name(const char *s)
*
* The 'timezone' field is optional; it defaults to +0000 if missing.
*/
time_t mutt_parse_date(const char *s, struct Tz *tz_out)
time_t mutt_date_parse_date(const char *s, struct Tz *tz_out)
{
int count = 0;
char *t = NULL;
Expand Down Expand Up @@ -492,7 +492,7 @@ time_t mutt_parse_date(const char *s, struct Tz *tz_out)
break;

case 1: /* month of the year */
i = mutt_check_month(t);
i = mutt_date_check_month(t);
if ((i < 0) || (i > 11))
return -1;
tm.tm_mon = i;
Expand Down Expand Up @@ -595,7 +595,7 @@ time_t mutt_parse_date(const char *s, struct Tz *tz_out)
tz_out->zoccident = zoccident;
}

time_t time = mutt_mktime(&tm, 0);
time_t time = mutt_date_make_time(&tm, 0);
/* Check we haven't overflowed the time (on 32-bit arches) */
if ((time != TIME_T_MAX) && (time != TIME_T_MIN))
time += tz_offset;
Expand All @@ -604,18 +604,18 @@ time_t mutt_parse_date(const char *s, struct Tz *tz_out)
}

/**
* imap_make_date - Format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz
* mutt_date_make_imap - Format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz
* @param buf Buffer to store the results
* @param buflen Length of buffer
* @param timestamp Time to format
* @retval int Number of characters written to buf
*
* Caller should provide a buffer of at least 27 bytes.
*/
int imap_make_date(char *buf, size_t buflen, time_t timestamp)
int mutt_date_make_imap(char *buf, size_t buflen, time_t timestamp)
{
struct tm *tm = localtime(&timestamp);
time_t tz = mutt_local_tz(timestamp);
time_t tz = mutt_date_local_tz(timestamp);

tz /= 60;

Expand All @@ -625,12 +625,12 @@ int imap_make_date(char *buf, size_t buflen, time_t timestamp)
}

/**
* imap_parse_date - Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz
* mutt_date_parse_imap - Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz
* @param s Date in string form
* @retval 0 Error
* @retval time_t Unix time
*/
time_t imap_parse_date(char *s)
time_t mutt_date_parse_imap(char *s)
{
struct tm t;
time_t tz;
Expand All @@ -640,7 +640,7 @@ time_t imap_parse_date(char *s)
if (*s != '-')
return 0;
s++;
t.tm_mon = mutt_check_month(s);
t.tm_mon = mutt_date_check_month(s);
s += 3;
if (*s != '-')
return 0;
Expand Down Expand Up @@ -674,5 +674,5 @@ time_t imap_parse_date(char *s)
if (s[0] == '+')
tz = -tz;

return (mutt_mktime(&t, 0) + tz);
return (mutt_date_make_time(&t, 0) + tz);
}
18 changes: 9 additions & 9 deletions mutt/date.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ extern const char *const Weekdays[];
extern const char *const Months[];
extern const struct Tz TimeZones[];

int imap_make_date(char *buf, size_t buflen, time_t timestamp);
time_t imap_parse_date(char *s);
bool is_day_name(const char *s);
int mutt_check_month(const char *s);
time_t mutt_local_tz(time_t t);
char *mutt_make_date(char *buf, size_t buflen);
time_t mutt_mktime(struct tm *t, int local);
void mutt_normalize_time(struct tm *tm);
time_t mutt_parse_date(const char *s, struct Tz *tz_out);
int mutt_date_check_month(const char *s);
bool mutt_date_is_day_name(const char *s);
time_t mutt_date_local_tz(time_t t);
char *mutt_date_make_date(char *buf, size_t buflen);
int mutt_date_make_imap(char *buf, size_t buflen, time_t timestamp);
time_t mutt_date_make_time(struct tm *t, int local);
void mutt_date_normalize_time(struct tm *tm);
time_t mutt_date_parse_date(const char *s, struct Tz *tz_out);
time_t mutt_date_parse_imap(char *s);

#endif /* _MUTT_DATE_H */
2 changes: 1 addition & 1 deletion ncrypt/gnupgparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static struct PgpKeyInfo *parse_pub_line(char *buf, int *is_subkey, struct PgpKe
p = tstr + 8;
goto bail;
}
tmp.gen_time = mutt_mktime(&time, 0);
tmp.gen_time = mutt_date_make_time(&time, 0);
break;
}
case 7: /* valid for n days */
Expand Down
8 changes: 4 additions & 4 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ int mutt_parse_rfc822_line(struct Envelope *e, struct Header *hdr, char *line,
if (hdr)
{
struct Tz tz;
hdr->date_sent = mutt_parse_date(p, &tz);
hdr->date_sent = mutt_date_parse_date(p, &tz);
if (hdr->date_sent > 0)
{
hdr->zhours = tz.zhours;
Expand All @@ -854,7 +854,7 @@ int mutt_parse_rfc822_line(struct Envelope *e, struct Header *hdr, char *line,

case 'e':
if ((mutt_strcasecmp("xpires", line + 1) == 0) && hdr &&
mutt_parse_date(p, NULL) < time(NULL))
mutt_date_parse_date(p, NULL) < time(NULL))
hdr->expired = true;
break;

Expand Down Expand Up @@ -1003,7 +1003,7 @@ int mutt_parse_rfc822_line(struct Envelope *e, struct Header *hdr, char *line,
char *d = strrchr(p, ';');

if (d)
hdr->received = mutt_parse_date(d + 1, NULL);
hdr->received = mutt_date_parse_date(d + 1, NULL);
}
}
break;
Expand Down Expand Up @@ -1190,7 +1190,7 @@ struct Envelope *mutt_read_rfc822_header(FILE *f, struct Header *hdr,
{
/* MH sometimes has the From_ line in the middle of the header! */
if (hdr && !hdr->received)
hdr->received = t - mutt_local_tz(t);
hdr->received = t - mutt_date_local_tz(t);
continue;
}

Expand Down
Loading

0 comments on commit 35a328e

Please sign in to comment.