commit 441e1b2
Merge pull request 'Add hh:mm times to posts, using the user timezone' (#530) from dandelions/snac2:exact-post-times into master Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/530
1 files changed,
+25,
-3
M
html.c
M
html.c
+25,
-3
1@@ -210,6 +210,28 @@ 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;
8+
9+ /* check if a user has actually set a timezone */
10+ if (user != NULL && xs_dict_get(user->config, "tz") != NULL &&
11+ (t = xs_parse_iso_date(date, 0)) != 0) {
12+ t += xs_tz_offset(user->tz);
13+
14+ time_t today = time(NULL);
15+ if (today - t >= 3600 * 24 * 30 * 6) {
16+ /* more than half a year ago */
17+ return xs_str_utctime(t, "%Y-%m-%d %H:%M");
18+ }
19+
20+ return xs_str_utctime(t, "%b%d %H:%M");
21+ }
22+
23+ return xs_crop_i(xs_dup(date), 0, 10);
24+}
25+
26+
27 xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
28 const char *udate, const char *url, int scope,
29 int in_people, const char *proxy, const char *lang,
30@@ -361,11 +383,11 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
31 xs_html_raw(" "));
32 }
33 else {
34- xs *date_label = xs_crop_i(xs_dup(date), 0, 10);
35+ xs *date_label = html_date_label(user, date);
36 xs *date_title = xs_dup(date);
37
38 if (!xs_is_null(udate)) {
39- xs *sd = xs_crop_i(xs_dup(udate), 0, 10);
40+ xs *sd = html_date_label(user, udate);
41
42 date_label = xs_str_cat(date_label, " / ", sd);
43
44@@ -4214,7 +4236,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
45 if (strcmp(type, "Follow") == 0 && pending_check(user, actor_id))
46 label = L("Follow Request");
47
48- xs *s_date = xs_crop_i(xs_dup(date), 0, 10);
49+ xs *s_date = html_date_label(user, date);
50
51 xs_html *this_html_label = xs_html_container(
52 xs_html_tag("b",