]> git.ipfire.org Git - thirdparty/git.git/blobdiff - date.c
date: use localtime() for "-local" time formats
[thirdparty/git.git] / date.c
diff --git a/date.c b/date.c
index 6eccbd85465761b51fc10b60bf411e2e0c9f530e..5580c40ac094211cb3d378b5b523a63308de0a2d 100644 (file)
--- a/date.c
+++ b/date.c
@@ -60,6 +60,12 @@ static struct tm *time_to_tm(unsigned long time, int tz)
        return gmtime(&t);
 }
 
+static struct tm *time_to_tm_local(unsigned long time)
+{
+       time_t t = time;
+       return localtime(&t);
+}
+
 /*
  * What value of "tz" was in effect back then at "time" in the
  * local timezone?
@@ -201,7 +207,10 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
                return timebuf.buf;
        }
 
-       tm = time_to_tm(time, tz);
+       if (mode->local)
+               tm = time_to_tm_local(time);
+       else
+               tm = time_to_tm(time, tz);
        if (!tm) {
                tm = time_to_tm(0, 0);
                tz = 0;
@@ -233,7 +242,8 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
                        month_names[tm->tm_mon], tm->tm_year + 1900,
                        tm->tm_hour, tm->tm_min, tm->tm_sec, tz);
        else if (mode->type == DATE_STRFTIME)
-               strbuf_addftime(&timebuf, mode->strftime_fmt, tm, tz, "");
+               strbuf_addftime(&timebuf, mode->strftime_fmt, tm, tz,
+                               mode->local ? NULL : "");
        else
                strbuf_addf(&timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
                                weekday_names[tm->tm_wday],