Skip to content

Commit

Permalink
Merge branch 'jn/parse-date-basic'
Browse files Browse the repository at this point in the history
* jn/parse-date-basic:
  Export parse_date_basic() to convert a date string to timestamp
  • Loading branch information
Junio C Hamano committed Aug 13, 2010
2 parents 1c80c9b + 9644c06 commit aa8b8f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
14 changes: 6 additions & 8 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}
Expand Down

0 comments on commit aa8b8f4

Please sign in to comment.