snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit ddc8781b3a93d77836b61f3efa884b3c23a1fd35
parent 5aaa6192ef08de7ab6c63e85708a1c825e9ff5f1
Author: default <nobody@localhost>
Date:   Sun, 12 Jan 2025 16:21:20 +0100

Minor improvements to start / end event time showing.

Diffstat:
Mhtml.c | 8++++----
Mxs.h | 5++---
Mxs_version.h | 2+-
3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/html.c b/html.c @@ -2275,18 +2275,18 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, if (strcmp(type, "Event") == 0) { /** Event start and end times **/ const char *s_time = xs_dict_get(msg, "startTime"); - if (xs_type(s_time) == XSTYPE_STRING) { + if (xs_is_string(s_time) && strlen(s_time) > 20) { const char *e_time = xs_dict_get(msg, "endTime"); const char *tz = xs_dict_get(msg, "timezone"); xs *s = xs_replace_i(xs_dup(s_time), "T", " "); xs *e = NULL; - if (xs_type(e_time) == XSTYPE_STRING) + if (xs_is_string(e_time) && strlen(e_time) > 20) e = xs_replace_i(xs_dup(e_time), "T", " "); /* if the event has a timezone, crop the offsets */ - if (xs_type(tz) == XSTYPE_STRING) { + if (xs_is_string(tz)) { s = xs_crop_i(s, 0, 19); if (e) @@ -2297,7 +2297,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, /* if start and end share the same day, crop it from the end */ if (e && memcmp(s, e, 11) == 0) - e = xs_crop_i(e, 11, strlen(e)); + e = xs_crop_i(e, 11, 0); if (e) s = xs_str_cat(s, " / ", e); diff --git a/xs.h b/xs.h @@ -626,15 +626,14 @@ int xs_between(const char *prefix, const char *str, const char *suffix) xs_str *xs_crop_i(xs_str *str, int start, int end) /* crops the string to be only from start to end */ { - XS_ASSERT_TYPE(str, XSTYPE_STRING); - int sz = strlen(str); if (end <= 0) end = sz + end; /* crop from the top */ - str[end] = '\0'; + if (end > 0 && end < sz) + str[end] = '\0'; /* crop from the bottom */ str = xs_collapse(str, 0, start); diff --git a/xs_version.h b/xs_version.h @@ -1 +1 @@ -/* cebb5663f26bc91b80c787525f5953b97839e0f7 2025-01-12T14:57:12+01:00 */ +/* b865e89769aedfdbc61251e94451e9d37579f52e 2025-01-12T16:17:47+01:00 */