]> granicus.if.org Git - neomutt/commitdiff
change date comparisons
authorEric Davis <edavis@insanum.com>
Mon, 1 Feb 2016 16:55:29 +0000 (16:55 +0000)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 02:33:06 +0000 (03:33 +0100)
now d = yesterday, w = last week, m = last month, y = last year, H =
last hour, etc from current time

hdrline.c

index c1ef190e458540c1a28df71f583b9a7254e88b2e..387d2be85350a348f7cffa11fdf3a39c069305da 100644 (file)
--- a/hdrline.c
+++ b/hdrline.c
@@ -331,10 +331,8 @@ hdr_format_str (char *dest,
 
        if (optional && (op == '[' || op == '(')) {
          char *is;
-          int d;
          T = time(NULL);
          tm = localtime(&T);
-         d = (T + tm->tm_gmtoff) % 86400;
          T -= (op == '(') ? hdr->received : hdr->date_sent;
 
          is = (char *)prefix;
@@ -345,34 +343,76 @@ hdr_format_str (char *dest,
 
          while( *is && *is != '?' ) {
            int t = strtol (is, &is, 10);
+           /* semi-broken (assuming 30 days in all months) */
            switch (*(is++)) {
-             case '?':
+             default:
                break;
+
              case 'y':
-               t *= 365 * 24 * 60 * 60;
+               if (t > 1)
+               {
+                 t--;
+                 t *= 365 * 24 * 60 * 60;
+               }
+               t += ((tm->tm_mon * 30 * 24 * 60 * 60) +
+                     (tm->tm_mday * 24 * 60 * 60) +
+                     (tm->tm_hour * 60 * 60) +
+                     (tm->tm_min * 60) +
+                     tm->tm_sec);
                break;
-             case 'M':
-               t *= 30 * 24 * 60 * 60;
+
+             case 'm':
+               if (t > 1)
+               {
+                 t--;
+                 t *= 30 * 24 * 60 * 60;
+               }
+               t += ((tm->tm_mday * 24 * 60 * 60) +
+                     (tm->tm_hour * 60 * 60) +
+                     (tm->tm_min * 60) +
+                     tm->tm_sec);
                break;
+
              case 'w':
-               t *= 7 * 24 * 60 * 60;
+               if (t > 1)
+               {
+                   t--;
+                   t *= 7 * 24 * 60 * 60;
+               }
+               t += ((tm->tm_wday * 24 * 60 * 60) +
+                     (tm->tm_hour * 60 * 60) +
+                     (tm->tm_min * 60) +
+                     tm->tm_sec);
                break;
+
              case 'd':
-               t *= 24 * 60 * 60;
-               break;
-             case 't':
-               if (t > 1) {
-                 t = (t-1) * 24 * 60 * 60;
-               } else {
-                 t = 0;
+               if (t > 1)
+               {
+                 t--;
+                 t *= (24 * 60 * 60);
                }
-               t += d;
+               t += ((tm->tm_hour * 60 * 60) +
+                     (tm->tm_min * 60) +
+                     tm->tm_sec);
                break;
-             case 'h':
-               t *= 60 * 60;
+
+             case 'H':
+               if (t > 1)
+               {
+                 t--;
+                 t *= (60 * 60);
+               }
+               t += ((tm->tm_min * 60) +
+                     tm->tm_sec);
                break;
-             case 'm':
-               t *= 60;
+
+             case 'M':
+               if (t > 1)
+               {
+                 t--;
+                 t *= (60);
+               }
+               t += (tm->tm_sec);
                break;
            }
            i += t;