Code

Merge git://git.kernel.org/pub/scm/gitk/gitk
[git.git] / date.c
diff --git a/date.c b/date.c
index db4c185431b504a5d5295e21c7c6c5f08cd54d55..7acb8cbd91bb1491931326ade1905d9c6f7bfdf5 100644 (file)
--- a/date.c
+++ b/date.c
@@ -4,9 +4,6 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 
-#include <time.h>
-#include <sys/time.h>
-
 #include "cache.h"
 
 static time_t my_mktime(struct tm *tm)
@@ -256,8 +253,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 +601,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 {