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>
Linus Torvalds committed
Sep 28, 2006 at 12:14 UTC
393d340e4f4ae571cd48387c29c85e9ab098b098
1 file changed
+40
date.c
+40
@@ -598,6 +598,32 @@ static void date_tea(struct tm *tm, int *num)
598
date_time(tm, 17);
599
}
600
601
+static void date_pm(struct tm *tm, int *num)
602
+{
603
+ int hour = *num;
604
+ *num = 0;
605
+
606
+ if (hour > 0 && hour < 12) {
607
+ tm->tm_hour = hour;
608
+ tm->tm_min = 0;
609
+ tm->tm_sec = 0;
610
+ }
611
+ if (tm->tm_hour > 0 && tm->tm_hour < 12)
612
+ tm->tm_hour += 12;
613
+}
614
+
615
+static void date_am(struct tm *tm, int *num)
616
+{
617
+ int hour = *num;
618
+ *num = 0;
619
+
620
+ if (hour > 0 && hour < 12) {
621
+ tm->tm_hour = hour;
622
+ tm->tm_min = 0;
623
+ tm->tm_sec = 0;
624
+ }
625
+}
626
+
627
static const struct special {
628
const char *name;
629
void (*fn)(struct tm *, int *);
@@ -606,6 +632,8 @@ static const struct special {
632
{ "noon", date_noon },
633
{ "midnight", date_midnight },
634
{ "tea", date_tea },
635
+ { "PM", date_pm },
636
+ { "AM", date_am },
637
{ NULL }
638
};
639
@@ -717,6 +745,18 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
745
char *end;
746
unsigned long number = strtoul(date, &end, 10);
747
748
+ switch (*end) {
749
+ case ':':
750
+ case '.':
751
+ case '/':
752
+ case '-':
753
+ if (isdigit(end[1])) {
754
+ int match = match_multi_number(number, *end, date, end, tm);
755
+ if (match)
756
+ return date + match;
757
+ }
758
+ }
759
+
760
*num = number;
761
return end;
762
}