From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: Re: Fix approxidate() to understand more extended numbers
Date: Fri, 29 Sep 2006 12:36:13 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0609291231560.3952@g5.osdl.org> (raw)
In-Reply-To: <7vslibno88.fsf@assigned-by-dhcp.cox.net>
On Fri, 29 Sep 2006, Junio C Hamano wrote:
> Linus Torvalds <torvalds@osdl.org> writes:
> >
> > If you write
> >
> > 12:30 am
> >
> > you really _should_ subtract 12, leaving you with 0:30. We don't. So we
> > end up with a 24-hour time of 12:30, which is obviously _pm_, and wrong.
> >
> > And "12 am" or "12 pm" doesn't work at all.
>
> Ah, that's what you meant. My brain a bit too tired from the
> day job tonight X-<.
Here's a patch that should work. It just simplifies the whole thing to say
"hour = (hour % 12) + X"
where X is 12 for PM and 0 for AM.
It also fixes the "exact date" parsing, which didn't parse AM at all, and
as such would do the same "12:30 AM" means "12:30 24-hour-format" bug. Of
course, I hope that no exact dates use AM/PM anyway, but since we support
the PM format, let's just get it right.
Not hugely tested, but I did test some of it, and it all _looks_ sane.
Linus
---
diff --git a/date.c b/date.c
index db4c185..1825922 100644
--- a/date.c
+++ b/date.c
@@ -256,8 +256,12 @@ static int match_alpha(const char *date,
}
if (match_string(date, "PM") == 2) {
- if (tm->tm_hour > 0 && tm->tm_hour < 12)
- tm->tm_hour += 12;
+ tm->tm_hour = (tm->tm_hour % 12) + 12;
+ return 2;
+ }
+
+ if (match_string(date, "AM") == 2) {
+ tm->tm_hour = (tm->tm_hour % 12) + 0;
return 2;
}
@@ -600,28 +604,30 @@ static void date_tea(struct tm *tm, int
static void date_pm(struct tm *tm, int *num)
{
- int hour = *num;
+ int hour, n = *num;
*num = 0;
- if (hour > 0 && hour < 12) {
- tm->tm_hour = hour;
+ hour = tm->tm_hour;
+ if (n) {
+ hour = n;
tm->tm_min = 0;
tm->tm_sec = 0;
}
- if (tm->tm_hour > 0 && tm->tm_hour < 12)
- tm->tm_hour += 12;
+ tm->tm_hour = (hour % 12) + 12;
}
static void date_am(struct tm *tm, int *num)
{
- int hour = *num;
+ int hour, n = *num;
*num = 0;
- if (hour > 0 && hour < 12) {
- tm->tm_hour = hour;
+ hour = tm->tm_hour;
+ if (n) {
+ hour = n;
tm->tm_min = 0;
tm->tm_sec = 0;
}
+ tm->tm_hour = (hour % 12);
}
static const struct special {
prev parent reply other threads:[~2006-09-29 19:36 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 ` Fix approxidate() to understand more extended numbers Linus Torvalds
2006-09-29 0:12 ` 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 [this message]
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.0609291231560.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).