diff options
author | Linus Torvalds <torvalds@osdl.org> | 2006-09-29 12:36:13 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-09-29 13:04:09 -0700 |
commit | 18b633cafcd43b83d752738fea62f185d4de1b91 (patch) | |
tree | 7ae588c6c22a1bf7b2f6f2ba5dccac390e9b2b4d | |
parent | bc1a5807575b2f34538d4158834da6524a4fc1f7 (diff) | |
download | git-18b633cafcd43b83d752738fea62f185d4de1b91.tar.gz |
Fix approxidate() to understand 12:34 AM/PM are 00:34 and 12:34
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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r-- | date.c | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -256,8 +256,12 @@ static int match_alpha(const char *date, struct tm *tm, int *offset) } 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 *num) 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 { |