summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
authorGravatar grunfink2026-01-25 10:29:56 +0100
committerGravatar grunfink2026-01-25 10:29:56 +0100
commit441e1b270651abfe5a09200f88855e8c67d70964 (patch)
tree5e79f6dc4f5e766bfacf7711018e4ebd49c70585 /html.c
parentMerge pull request 'Configurable limits for polls' (#534) from dandelions/sna... (diff)
parenttime-labels: fixed segfault (diff)
downloadsnac2-441e1b270651abfe5a09200f88855e8c67d70964.tar.gz
snac2-441e1b270651abfe5a09200f88855e8c67d70964.tar.xz
snac2-441e1b270651abfe5a09200f88855e8c67d70964.zip
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
Diffstat (limited to 'html.c')
-rw-r--r--html.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/html.c b/html.c
index 436995b..66ce738 100644
--- a/html.c
+++ b/html.c
@@ -210,6 +210,28 @@ xs_str *format_text_with_emoji(snac *user, const char *text, int ems, const char
210} 210}
211 211
212 212
213xs_str *html_date_label(snac *user, const char *date)
214{
215 time_t t;
216
217 /* check if a user has actually set a timezone */
218 if (user != NULL && xs_dict_get(user->config, "tz") != NULL &&
219 (t = xs_parse_iso_date(date, 0)) != 0) {
220 t += xs_tz_offset(user->tz);
221
222 time_t today = time(NULL);
223 if (today - t >= 3600 * 24 * 30 * 6) {
224 /* more than half a year ago */
225 return xs_str_utctime(t, "%Y-%m-%d %H:%M");
226 }
227
228 return xs_str_utctime(t, "%b%d %H:%M");
229 }
230
231 return xs_crop_i(xs_dup(date), 0, 10);
232}
233
234
213xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date, 235xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
214 const char *udate, const char *url, int scope, 236 const char *udate, const char *url, int scope,
215 int in_people, const char *proxy, const char *lang, 237 int in_people, const char *proxy, const char *lang,
@@ -361,11 +383,11 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
361 xs_html_raw(" ")); 383 xs_html_raw(" "));
362 } 384 }
363 else { 385 else {
364 xs *date_label = xs_crop_i(xs_dup(date), 0, 10); 386 xs *date_label = html_date_label(user, date);
365 xs *date_title = xs_dup(date); 387 xs *date_title = xs_dup(date);
366 388
367 if (!xs_is_null(udate)) { 389 if (!xs_is_null(udate)) {
368 xs *sd = xs_crop_i(xs_dup(udate), 0, 10); 390 xs *sd = html_date_label(user, udate);
369 391
370 date_label = xs_str_cat(date_label, " / ", sd); 392 date_label = xs_str_cat(date_label, " / ", sd);
371 393
@@ -4214,7 +4236,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
4214 if (strcmp(type, "Follow") == 0 && pending_check(user, actor_id)) 4236 if (strcmp(type, "Follow") == 0 && pending_check(user, actor_id))
4215 label = L("Follow Request"); 4237 label = L("Follow Request");
4216 4238
4217 xs *s_date = xs_crop_i(xs_dup(date), 0, 10); 4239 xs *s_date = html_date_label(user, date);
4218 4240
4219 xs_html *this_html_label = xs_html_container( 4241 xs_html *this_html_label = xs_html_container(
4220 xs_html_tag("b", 4242 xs_html_tag("b",