git log: support "auto" decorations
[gitweb.git] / date.c
diff --git a/date.c b/date.c
index 83b4166344b31ea615603acaeb95a873f2c05077..782de95d90c6ac1a02ddfa0df81ca93ecdf910c4 100644 (file)
--- a/date.c
+++ b/date.c
@@ -144,8 +144,8 @@ void show_date_relative(unsigned long time, int tz,
                if (months) {
                        struct strbuf sb = STRBUF_INIT;
                        strbuf_addf(&sb, Q_("%lu year", "%lu years", years), years);
-                       /* TRANSLATORS: "%s" is "<n> years" */
                        strbuf_addf(timebuf,
+                                /* TRANSLATORS: "%s" is "<n> years" */
                                 Q_("%s, %lu month ago", "%s, %lu months ago", months),
                                 sb.buf, months);
                        strbuf_release(&sb);
@@ -184,8 +184,10 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
                tz = local_tzoffset(time);
 
        tm = time_to_tm(time, tz);
-       if (!tm)
-               return NULL;
+       if (!tm) {
+               tm = time_to_tm(0, 0);
+               tz = 0;
+       }
 
        strbuf_reset(&timebuf);
        if (mode == DATE_SHORT)
@@ -1113,3 +1115,20 @@ unsigned long approxidate_careful(const char *date, int *error_ret)
        gettimeofday(&tv, NULL);
        return approxidate_str(date, &tv, error_ret);
 }
+
+int date_overflows(unsigned long t)
+{
+       time_t sys;
+
+       /* If we overflowed our unsigned long, that's bad... */
+       if (t == ULONG_MAX)
+               return 1;
+
+       /*
+        * ...but we also are going to feed the result to system
+        * functions that expect time_t, which is often "signed long".
+        * Make sure that we fit into time_t, as well.
+        */
+       sys = t;
+       return t != sys || (t < 1) != (sys < 1);
+}