summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2025-01-12 16:21:20 +0100
committerGravatar default2025-01-12 16:21:20 +0100
commitddc8781b3a93d77836b61f3efa884b3c23a1fd35 (patch)
tree1b5678c398298df4b8bc439fb79827fcb5ce2ce4
parentBetter dangling hashtag checking. (diff)
downloadpenes-snac2-ddc8781b3a93d77836b61f3efa884b3c23a1fd35.tar.gz
penes-snac2-ddc8781b3a93d77836b61f3efa884b3c23a1fd35.tar.xz
penes-snac2-ddc8781b3a93d77836b61f3efa884b3c23a1fd35.zip
Minor improvements to start / end event time showing.
-rw-r--r--html.c8
-rw-r--r--xs.h5
-rw-r--r--xs_version.h2
3 files changed, 7 insertions, 8 deletions
diff --git a/html.c b/html.c
index 322bafa..c55937d 100644
--- a/html.c
+++ b/html.c
@@ -2275,18 +2275,18 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
2275 if (strcmp(type, "Event") == 0) { /** Event start and end times **/ 2275 if (strcmp(type, "Event") == 0) { /** Event start and end times **/
2276 const char *s_time = xs_dict_get(msg, "startTime"); 2276 const char *s_time = xs_dict_get(msg, "startTime");
2277 2277
2278 if (xs_type(s_time) == XSTYPE_STRING) { 2278 if (xs_is_string(s_time) && strlen(s_time) > 20) {
2279 const char *e_time = xs_dict_get(msg, "endTime"); 2279 const char *e_time = xs_dict_get(msg, "endTime");
2280 const char *tz = xs_dict_get(msg, "timezone"); 2280 const char *tz = xs_dict_get(msg, "timezone");
2281 2281
2282 xs *s = xs_replace_i(xs_dup(s_time), "T", " "); 2282 xs *s = xs_replace_i(xs_dup(s_time), "T", " ");
2283 xs *e = NULL; 2283 xs *e = NULL;
2284 2284
2285 if (xs_type(e_time) == XSTYPE_STRING) 2285 if (xs_is_string(e_time) && strlen(e_time) > 20)
2286 e = xs_replace_i(xs_dup(e_time), "T", " "); 2286 e = xs_replace_i(xs_dup(e_time), "T", " ");
2287 2287
2288 /* if the event has a timezone, crop the offsets */ 2288 /* if the event has a timezone, crop the offsets */
2289 if (xs_type(tz) == XSTYPE_STRING) { 2289 if (xs_is_string(tz)) {
2290 s = xs_crop_i(s, 0, 19); 2290 s = xs_crop_i(s, 0, 19);
2291 2291
2292 if (e) 2292 if (e)
@@ -2297,7 +2297,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
2297 2297
2298 /* if start and end share the same day, crop it from the end */ 2298 /* if start and end share the same day, crop it from the end */
2299 if (e && memcmp(s, e, 11) == 0) 2299 if (e && memcmp(s, e, 11) == 0)
2300 e = xs_crop_i(e, 11, strlen(e)); 2300 e = xs_crop_i(e, 11, 0);
2301 2301
2302 if (e) 2302 if (e)
2303 s = xs_str_cat(s, " / ", e); 2303 s = xs_str_cat(s, " / ", e);
diff --git a/xs.h b/xs.h
index 45952c9..05d84f5 100644
--- a/xs.h
+++ b/xs.h
@@ -626,15 +626,14 @@ int xs_between(const char *prefix, const char *str, const char *suffix)
626xs_str *xs_crop_i(xs_str *str, int start, int end) 626xs_str *xs_crop_i(xs_str *str, int start, int end)
627/* crops the string to be only from start to end */ 627/* crops the string to be only from start to end */
628{ 628{
629 XS_ASSERT_TYPE(str, XSTYPE_STRING);
630
631 int sz = strlen(str); 629 int sz = strlen(str);
632 630
633 if (end <= 0) 631 if (end <= 0)
634 end = sz + end; 632 end = sz + end;
635 633
636 /* crop from the top */ 634 /* crop from the top */
637 str[end] = '\0'; 635 if (end > 0 && end < sz)
636 str[end] = '\0';
638 637
639 /* crop from the bottom */ 638 /* crop from the bottom */
640 str = xs_collapse(str, 0, start); 639 str = xs_collapse(str, 0, start);
diff --git a/xs_version.h b/xs_version.h
index ce3d06b..12f713a 100644
--- 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 */