git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>, Git Mailing List <git@vger.kernel.org>
Subject: Fix approxidate() to understand more extended numbers
Date: Thu, 28 Sep 2006 12:14:27 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0609281212380.3952@g5.osdl.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0609281211260.3952@g5.osdl.org>


You can now say "5:35 PM yesterday", and approxidate() gets the right answer.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

Useful? Of course. In a sick and twisted sort of way.

Try to say "yesterday at 5 PM" before and after this. It _really_ was 
confused before.

diff --git a/date.c b/date.c
index 4ff6604..db4c185 100644
--- a/date.c
+++ b/date.c
@@ -598,6 +598,32 @@ static void date_tea(struct tm *tm, int 
 	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(con
 	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;
 }

  reply	other threads:[~2006-09-28 19:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-28 19:12 Clean up approxidate() in preparation for fixes Linus Torvalds
2006-09-28 19:14 ` Linus Torvalds [this message]
2006-09-29  0:12   ` Fix approxidate() to understand more extended numbers Morten Welinder
2006-09-29  6:03     ` Linus Torvalds
2006-09-29  6:14       ` Junio C Hamano
2006-09-29  6:42         ` Linus Torvalds
2006-09-29  7:09           ` Junio C Hamano
2006-09-29 14:04             ` Johannes Schindelin
2006-09-29 19:36             ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0609281212380.3952@g5.osdl.org \
    --to=torvalds@osdl.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).