Skip to content

Commit

Permalink
Fix approxidate() to understand more extended numbers
Browse files Browse the repository at this point in the history
You can now say "5:35 PM yesterday", and approxidate() gets the right answer.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Sep 29, 2006
1 parent e92a54d commit 393d340
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,32 @@ static void date_tea(struct tm *tm, int *num)
date_time(tm, 17);
}

static void date_pm(struct tm *tm, int *num)
{
int hour = *num;
*num = 0;

if (hour > 0 && hour < 12) {
tm->tm_hour = hour;
tm->tm_min = 0;
tm->tm_sec = 0;
}
if (tm->tm_hour > 0 && tm->tm_hour < 12)
tm->tm_hour += 12;
}

static void date_am(struct tm *tm, int *num)
{
int hour = *num;
*num = 0;

if (hour > 0 && hour < 12) {
tm->tm_hour = hour;
tm->tm_min = 0;
tm->tm_sec = 0;
}
}

static const struct special {
const char *name;
void (*fn)(struct tm *, int *);
Expand All @@ -606,6 +632,8 @@ static const struct special {
{ "noon", date_noon },
{ "midnight", date_midnight },
{ "tea", date_tea },
{ "PM", date_pm },
{ "AM", date_am },
{ NULL }
};

Expand Down Expand Up @@ -717,6 +745,18 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
char *end;
unsigned long number = strtoul(date, &end, 10);

switch (*end) {
case ':':
case '.':
case '/':
case '-':
if (isdigit(end[1])) {
int match = match_multi_number(number, *end, date, end, tm);
if (match)
return date + match;
}
}

*num = number;
return end;
}
Expand Down

0 comments on commit 393d340

Please sign in to comment.