summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-06 22:28:59 (GMT)
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-06 22:28:59 (GMT)
commitf80cd783c6f346388bbb0a6a15672be99a71f7ed (patch)
tree0c201e2e8bac61dc0189a857b061a796c1913cd4 /date.c
parent5aad72f2bc1527e1fcdf460f0a36b0bcc4117b4a (diff)
downloadgit-f80cd783c6f346388bbb0a6a15672be99a71f7ed.zip
git-f80cd783c6f346388bbb0a6a15672be99a71f7ed.tar.gz
git-f80cd783c6f346388bbb0a6a15672be99a71f7ed.tar.bz2
date.c: add "show_date()" function.
Kind of like ctime(), but not as broken.
Diffstat (limited to 'date.c')
-rw-r--r--date.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/date.c b/date.c
index aa4fb3e..7371bc1 100644
--- a/date.c
+++ b/date.c
@@ -39,6 +39,34 @@ static const char *weekday_names[] = {
};
/*
+ * 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 = (tz / 100)*60 + (tz % 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.
*
* In my world, it's always summer, and things are probably a bit off