diff options
author | Jonathan Nieder <jrnieder@gmail.com> | 2010-07-15 18:22:57 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-07-15 15:35:12 -0700 |
commit | 9644c0616374f8c621b10793b1732b26a0482820 (patch) | |
tree | 8d241d7c138a4f2855a50a5657ab9429f9c91547 /date.c | |
parent | 53b304224a561b5fd4ae35cedc0a978d91d4b1da (diff) | |
download | git-9644c0616374f8c621b10793b1732b26a0482820.tar.gz |
Export parse_date_basic() to convert a date string to timestamp
approxidate() is not appropriate for reading machine-written dates
because it guesses instead of erroring out on malformed dates.
parse_date() is less convenient since it returns its output as a
string. So export the underlying function that writes a timestamp.
While at it, change the return value to match the usual convention:
return 0 for success and -1 for failure.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Acked-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'date.c')
-rw-r--r-- | date.c | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -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, ×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) @@ -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, ×tamp, &offset) > 0) + if (!parse_date_basic(date, ×tamp, &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, ×tamp, &offset) > 0) { + if (!parse_date_basic(date, ×tamp, &offset)) { *error_ret = 0; return timestamp; } |