summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 53b3042)
raw | patch | inline | side by side (parent: 53b3042)
author | Jonathan Nieder <jrnieder@gmail.com> | |
Thu, 15 Jul 2010 16:22:57 +0000 (18:22 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 15 Jul 2010 22:35:12 +0000 (15:35 -0700) |
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>
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>
cache.h | patch | blob | history | |
date.c | patch | blob | history |
index c9fa3df7f5b343ecea980ceb423e7c23d2eb22b2..68258be97d84e4d023dccc748c8220b9892bc6cb 100644 (file)
--- a/cache.h
+++ b/cache.h
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 *);
index 3c981f7eb5ebaed1ba621f3d4cd960f14145b97a..00f9eb5d0b9730107a8e08e92eb04d4cc9233595 100644 (file)
--- a/date.c
+++ b/date.c
/* 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);
}
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;
}