commit 2890fe2

green  ·  2025-04-16 00:30:29 +0000 UTC
parent c6b411a
small: timezone dependant date labels
1 files changed,  +24, -3
M html.c
M html.c
+24, -3
 1@@ -210,6 +210,27 @@ xs_str *format_text_with_emoji(snac *user, const char *text, int ems, const char
 2 }
 3 
 4 
 5+xs_str *html_date_label(snac *user, const char *date)
 6+{
 7+    time_t t = xs_parse_iso_date(date, 0);
 8+
 9+    /* check if a user has actually set a timezone */
10+    if (t != 0 && xs_dict_get(user->config, "tz") != NULL) {
11+        t += xs_tz_offset(user->tz);
12+
13+        time_t today = time(NULL);
14+        if (today - t >= 3600 * 24 * 30 * 6) {
15+            /* more than half a year ago */
16+            return xs_str_utctime(t, "%Y-%m-%d %H:%M");
17+        }
18+
19+        return xs_str_utctime(t, "%b%d %H:%M");
20+    }
21+
22+    return xs_crop_i(xs_dup(date), 0, 10);
23+}
24+
25+
26 xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
27                         const char *udate, const char *url, int scope,
28                         int in_people, const char *proxy, const char *lang,
29@@ -361,11 +382,11 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
30             xs_html_raw(" "));
31     }
32     else {
33-        xs *date_label = xs_crop_i(xs_dup(date), 0, 10);
34+        xs *date_label = html_date_label(user, date);
35         xs *date_title = xs_dup(date);
36 
37         if (!xs_is_null(udate)) {
38-            xs *sd = xs_crop_i(xs_dup(udate), 0, 10);
39+            xs *sd = html_date_label(user, udate);
40 
41             date_label = xs_str_cat(date_label, " / ", sd);
42 
43@@ -4203,7 +4224,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
44         if (strcmp(type, "Follow") == 0 && pending_check(user, actor_id))
45             label = L("Follow Request");
46 
47-        xs *s_date = xs_crop_i(xs_dup(date), 0, 10);
48+        xs *s_date = html_date_label(user, date);
49 
50         xs_html *this_html_label = xs_html_container(
51                 xs_html_tag("b",