commit 6d0b0cd

default  ·  2025-01-12 13:31:45 +0000 UTC
parent 6154ce7
Show event start / end times.

This code is a ugly as fuck.
1 files changed,  +43, -0
M html.c
M html.c
+43, -0
 1@@ -2272,6 +2272,49 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
 2         }
 3     }
 4 
 5+    if (strcmp(type, "Event") == 0) { /** Event start and end times **/
 6+        const char *s_time = xs_dict_get(msg, "startTime");
 7+
 8+        if (xs_type(s_time) == XSTYPE_STRING) {
 9+            const char *e_time = xs_dict_get(msg, "endTime");
10+            const char *tz     = xs_dict_get(msg, "timezone");
11+
12+            xs *s = xs_replace_i(xs_dup(s_time), "T", " ");
13+            xs *e = NULL;
14+
15+            if (xs_type(e_time) == XSTYPE_STRING)
16+                e = xs_replace_i(xs_dup(e_time), "T", " ");
17+
18+            /* if the event has a timezone, crop the offsets */
19+            if (xs_type(tz) == XSTYPE_STRING) {
20+                s = xs_crop_i(s, 0, 19);
21+
22+                if (e)
23+                    e = xs_crop_i(e, 0, 19);
24+            }
25+            else
26+                tz = "";
27+
28+            /* if start and end share the same day, crop it from the end */
29+            if (e && memcmp(s, e, 11) == 0)
30+                e = xs_crop_i(e, 11, strlen(e));
31+
32+            if (e)
33+                s = xs_str_cat(s, " / ", e);
34+
35+            if (*tz)
36+                s = xs_str_cat(s, " (", tz, ")");
37+
38+            /* replace ugly decimals */
39+            s = xs_replace_i(s, ".000", "");
40+
41+            xs_html_add(snac_content_wrap,
42+                xs_html_tag("p",
43+                    xs_html_text(L("Time: ")),
44+                    xs_html_text(s)));
45+        }
46+    }
47+
48     /* show all hashtags that has not been shown previously in the content */
49     const xs_list *tags = xs_dict_get(msg, "tag");
50     if (xs_type(tags) == XSTYPE_LIST && xs_list_len(tags)) {