commit 3047f62

default  ·  2023-06-27 15:08:09 +0000 UTC
parent f543185
For polls, shows a 'Closes in d:h:m:s' string.
1 files changed,  +22, -6
M html.c
M html.c
+22, -6
 1@@ -1025,12 +1025,6 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
 2                 }
 3 
 4                 c = xs_str_cat(c, "</table>\n");
 5-
 6-                /* if it's *really* closed, say it */
 7-                if (closed == 2) {
 8-                    xs *s1 = xs_fmt("<p>%s</p>\n", L("Closed"));
 9-                    c = xs_str_cat(c, s1);
10-                }
11             }
12             else {
13                 /* poll still active */
14@@ -1061,6 +1055,28 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
15 
16                 c = xs_str_cat(c, s1);
17             }
18+
19+            /* if it's *really* closed, say it */
20+            if (closed == 2) {
21+                xs *s1 = xs_fmt("<p>%s</p>\n", L("Closed"));
22+                c = xs_str_cat(c, s1);
23+            }
24+            else {
25+                /* show when the poll closes */
26+                const char *end_time = xs_dict_get(msg, "endTime");
27+                if (!xs_is_null(end_time)) {
28+                    time_t t0 = time(NULL);
29+                    time_t t1 = xs_parse_iso_date(end_time, 0);
30+
31+                    if (t1 > 0 && t1 > t0) {
32+                        time_t diff_time = t1 - t0;
33+                        xs *tf = xs_str_time_diff(diff_time);
34+
35+                        xs *s1 = xs_fmt("<p>%s %s</p>", L("Closes in"), tf);
36+                        c = xs_str_cat(c, s1);
37+                    }
38+                }
39+            }
40         }
41 
42         s = xs_str_cat(s, c);