summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2010-08-12 18:31:03 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-08-12 18:31:03 -0700
commitaa8b8f40df07972fad357420415ff9bbdf22dd9e (patch)
tree6c7200dbc490fcd5f5511e3c13d6bd0f58e9bbba
parentMerge branch 'sp/fix-smart-http-deadlock-on-error' (diff)
parentExport parse_date_basic() to convert a date string to timestamp (diff)
downloadtgif-aa8b8f40df07972fad357420415ff9bbdf22dd9e.tar.xz
Merge branch 'jn/parse-date-basic'
* jn/parse-date-basic: Export parse_date_basic() to convert a date string to timestamp
-rw-r--r--cache.h1
-rw-r--r--date.c14
2 files changed, 7 insertions, 8 deletions
diff --git a/cache.h b/cache.h
index 1e690d1240..37ef9d8a00 100644
--- a/cache.h
+++ b/cache.h
@@ -811,6 +811,7 @@ const char *show_date_relative(unsigned long time, int tz,
char *timebuf,
size_t timebuf_size);
int parse_date(const char *date, char *buf, int bufsize);
+int parse_date_basic(const char *date, unsigned long *timestamp, int *offset);
void datestamp(char *buf, int bufsize);
#define approxidate(s) approxidate_careful((s), NULL)
unsigned long approxidate_careful(const char *, int *);
diff --git a/date.c b/date.c
index 3c981f7eb5..00f9eb5d0b 100644
--- a/date.c
+++ b/date.c
@@ -586,7 +586,7 @@ static int date_string(unsigned long date, int offset, char *buf, int len)
/* 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;
@@ -642,17 +642,16 @@ int parse_date_toffset(const char *date, unsigned long *timestamp, int *offset)
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, &timestamp, &offset) > 0)
- return date_string(timestamp, offset, result, maxlen);
- else
+ if (parse_date_basic(date, &timestamp, &offset))
return -1;
+ return date_string(timestamp, offset, result, maxlen);
}
enum date_mode parse_date_format(const char *format)
@@ -1004,9 +1003,8 @@ unsigned long approxidate_relative(const char *date, const struct timeval *tv)
int offset;
int errors = 0;
- if (parse_date_toffset(date, &timestamp, &offset) > 0)
+ if (!parse_date_basic(date, &timestamp, &offset))
return timestamp;
-
return approxidate_str(date, tv, &errors);
}
@@ -1019,7 +1017,7 @@ unsigned long approxidate_careful(const char *date, int *error_ret)
if (!error_ret)
error_ret = &dummy;
- if (parse_date_toffset(date, &timestamp, &offset) > 0) {
+ if (!parse_date_basic(date, &timestamp, &offset)) {
*error_ret = 0;
return timestamp;
}