summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@osdl.org>2006-09-28 12:14:27 -0700
committerJunio C Hamano <junkio@cox.net>2006-09-28 18:25:25 -0700
commit393d340e4f4ae571cd48387c29c85e9ab098b098 (patch)
tree30b3d8824d861225d864c4358f9549e9f194b85e /date.c
parente92a54d99cb36eab6e29069fe3b135e6e6b24f12 (diff)
downloadgit-393d340e4f4ae571cd48387c29c85e9ab098b098.tar.gz
Fix approxidate() to understand more extended numbers
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>
Diffstat (limited to 'date.c')
-rw-r--r--date.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/date.c b/date.c
index 4ff6604a09..db4c185431 100644
--- a/date.c
+++ b/date.c
@@ -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 *);
@@ -606,6 +632,8 @@ static const struct special {
{ "noon", date_noon },
{ "midnight", date_midnight },
{ "tea", date_tea },
+ { "PM", date_pm },
+ { "AM", date_am },
{ NULL }
};
@@ -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;
}