Code

git-apply: creatign empty files is nonfatal
[git.git] / date.c
diff --git a/date.c b/date.c
index aa4fb3efef5f35d510c14c3a73d497143406f5e7..ff922fe4fc896f4d1132ae84ab5fa74c7f582484 100644 (file)
--- a/date.c
+++ b/date.c
@@ -4,12 +4,11 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <ctype.h>
 #include <time.h>
 
+#include "cache.h"
+
 static time_t my_mktime(struct tm *tm)
 {
        static const int mdays[] = {
@@ -38,6 +37,34 @@ static const char *weekday_names[] = {
        "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
 };
 
+/*
+ * The "tz" thing is passed in as this strange "decimal parse of tz"
+ * thing, which means that tz -0100 is passed in as the integer -100,
+ * even though it means "sixty minutes off"
+ */
+const char *show_date(unsigned long time, int tz)
+{
+       struct tm *tm;
+       time_t t;
+       static char timebuf[200];
+       int minutes;
+
+       minutes = tz < 0 ? -tz : tz;
+       minutes = (minutes / 100)*60 + (minutes % 100);
+       minutes = tz < 0 ? -minutes : minutes;
+       t = time + minutes * 60;
+       tm = gmtime(&t);
+       if (!tm)
+               return NULL;
+       sprintf(timebuf, "%.3s %.3s %d %02d:%02d:%02d %d %+05d",
+               weekday_names[tm->tm_wday],
+               month_names[tm->tm_mon],
+               tm->tm_mday,
+               tm->tm_hour, tm->tm_min, tm->tm_sec,
+               tm->tm_year + 1900, tz);
+       return timebuf;
+}
+
 /*
  * Check these. And note how it doesn't do the summer-time conversion.
  *