}
/* Give years and months for 5 years or so */
if (diff < 1825) {
- unsigned long years = diff / 365;
- unsigned long months = (diff % 365 + 15) / 30;
+ unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
+ unsigned long years = totalmonths / 12;
+ unsigned long months = totalmonths % 12;
int n;
n = snprintf(timebuf, timebuf_size, "%lu year%s",
years, (years > 1 ? "s" : ""));
/* Gr. strptime is crap for this; it doesn't have a way to require RFC2822
(i.e. English) day/month names, and it doesn't work correctly with %z. */
-int parse_date_toffset(const char *date, unsigned long *timestamp, int *offset)
+int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
{
struct tm tm;
int tm_gmt;
/* mktime uses local timezone */
*timestamp = tm_to_time_t(&tm);
if (*offset == -1)
- *offset = (*timestamp - mktime(&tm)) / 60;
+ *offset = ((time_t)*timestamp - mktime(&tm)) / 60;
if (*timestamp == -1)
return -1;
if (!tm_gmt)
*timestamp -= *offset * 60;
- return 1; /* success */
+ return 0; /* success */
}
int parse_date(const char *date, char *result, int maxlen)
{
unsigned long timestamp;
int offset;
- if (parse_date_toffset(date, ×tamp, &offset) > 0)
- return date_string(timestamp, offset, result, maxlen);
- else
+ if (parse_date_basic(date, ×tamp, &offset))
return -1;
+ return date_string(timestamp, offset, result, maxlen);
}
enum date_mode parse_date_format(const char *format)
int offset;
int errors = 0;
- if (parse_date_toffset(date, ×tamp, &offset) > 0)
+ if (!parse_date_basic(date, ×tamp, &offset))
return timestamp;
-
return approxidate_str(date, tv, &errors);
}
if (!error_ret)
error_ret = &dummy;
- if (parse_date_toffset(date, ×tamp, &offset) > 0) {
+ if (!parse_date_basic(date, ×tamp, &offset)) {
*error_ret = 0;
return timestamp;
}