commit ddc8781

default  ·  2025-01-12 15:21:20 +0000 UTC
parent 5aaa619
Minor improvements to start / end event time showing.
3 files changed,  +7, -8
M html.c
M xs.h
M html.c
+4, -4
 1@@ -2275,18 +2275,18 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
 2     if (strcmp(type, "Event") == 0) { /** Event start and end times **/
 3         const char *s_time = xs_dict_get(msg, "startTime");
 4 
 5-        if (xs_type(s_time) == XSTYPE_STRING) {
 6+        if (xs_is_string(s_time) && strlen(s_time) > 20) {
 7             const char *e_time = xs_dict_get(msg, "endTime");
 8             const char *tz     = xs_dict_get(msg, "timezone");
 9 
10             xs *s = xs_replace_i(xs_dup(s_time), "T", " ");
11             xs *e = NULL;
12 
13-            if (xs_type(e_time) == XSTYPE_STRING)
14+            if (xs_is_string(e_time) && strlen(e_time) > 20)
15                 e = xs_replace_i(xs_dup(e_time), "T", " ");
16 
17             /* if the event has a timezone, crop the offsets */
18-            if (xs_type(tz) == XSTYPE_STRING) {
19+            if (xs_is_string(tz)) {
20                 s = xs_crop_i(s, 0, 19);
21 
22                 if (e)
23@@ -2297,7 +2297,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
24 
25             /* if start and end share the same day, crop it from the end */
26             if (e && memcmp(s, e, 11) == 0)
27-                e = xs_crop_i(e, 11, strlen(e));
28+                e = xs_crop_i(e, 11, 0);
29 
30             if (e)
31                 s = xs_str_cat(s, " / ", e);
M xs.h
+2, -3
 1@@ -626,15 +626,14 @@ int xs_between(const char *prefix, const char *str, const char *suffix)
 2 xs_str *xs_crop_i(xs_str *str, int start, int end)
 3 /* crops the string to be only from start to end */
 4 {
 5-    XS_ASSERT_TYPE(str, XSTYPE_STRING);
 6-
 7     int sz = strlen(str);
 8 
 9     if (end <= 0)
10         end = sz + end;
11 
12     /* crop from the top */
13-    str[end] = '\0';
14+    if (end > 0 && end < sz)
15+        str[end] = '\0';
16 
17     /* crop from the bottom */
18     str = xs_collapse(str, 0, start);
+1, -1
1@@ -1 +1 @@
2-/* cebb5663f26bc91b80c787525f5953b97839e0f7 2025-01-12T14:57:12+01:00 */
3+/* b865e89769aedfdbc61251e94451e9d37579f52e 2025-01-12T16:17:47+01:00 */