summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--html.c10
-rw-r--r--xs_time.h71
2 files changed, 78 insertions, 3 deletions
diff --git a/html.c b/html.c
index b5d8946..afbc716 100644
--- a/html.c
+++ b/html.c
@@ -4359,19 +4359,23 @@ int html_post_handler(const xs_dict *req, const char *q_path,
4359 } 4359 }
4360 4360
4361 if (xs_is_string(post_date) && *post_date) { 4361 if (xs_is_string(post_date) && *post_date) {
4362 xs *local_pubdate = xs_fmt("%sT%s", post_date, 4362 xs *post_pubdate = xs_fmt("%sT%s", post_date,
4363 xs_is_string(post_time) && *post_time ? post_time : "00:00:00"); 4363 xs_is_string(post_time) && *post_time ? post_time : "00:00:00");
4364 4364
4365 time_t t = xs_parse_iso_date(local_pubdate, 1); 4365 time_t t = xs_parse_iso_date(post_pubdate, 0);
4366 4366
4367 if (t != 0) { 4367 if (t != 0) {
4368 const char *tz = xs_dict_get_def(snac.config, "tz", "UTC");
4369
4370 t -= xs_tz_offset(tz);
4371
4368 xs *iso_date = xs_str_iso_date(t); 4372 xs *iso_date = xs_str_iso_date(t);
4369 msg = xs_dict_set(msg, "published", iso_date); 4373 msg = xs_dict_set(msg, "published", iso_date);
4370 4374
4371 snac_debug(&snac, 1, xs_fmt("Published date: [%s]", iso_date)); 4375 snac_debug(&snac, 1, xs_fmt("Published date: [%s]", iso_date));
4372 } 4376 }
4373 else 4377 else
4374 snac_log(&snac, xs_fmt("Invalid post date: [%s]", local_pubdate)); 4378 snac_log(&snac, xs_fmt("Invalid post date: [%s]", post_pubdate));
4375 } 4379 }
4376 4380
4377 /* is the published date from the future? */ 4381 /* is the published date from the future? */
diff --git a/xs_time.h b/xs_time.h
index 0e004dc..eaced75 100644
--- a/xs_time.h
+++ b/xs_time.h
@@ -15,6 +15,8 @@ time_t xs_parse_time(const char *str, const char *fmt, int local);
15#define xs_parse_localtime(str, fmt) xs_parse_time(str, fmt, 1) 15#define xs_parse_localtime(str, fmt) xs_parse_time(str, fmt, 1)
16#define xs_parse_utctime(str, fmt) xs_parse_time(str, fmt, 0) 16#define xs_parse_utctime(str, fmt) xs_parse_time(str, fmt, 0)
17xs_str *xs_str_time_diff(time_t time_diff); 17xs_str *xs_str_time_diff(time_t time_diff);
18xs_list *xs_tz_list(void);
19int xs_tz_offset(const char *tz);
18 20
19#ifdef XS_IMPLEMENTATION 21#ifdef XS_IMPLEMENTATION
20 22
@@ -106,6 +108,75 @@ time_t xs_parse_iso_date(const char *iso_date, int local)
106} 108}
107 109
108 110
111/** timezones **/
112
113/* intentionally dead simple */
114
115struct {
116 const char *tz; /* timezone name */
117 float h_offset; /* hour offset */
118} xs_tz[] = {
119 { "UTC", 0 },
120 { "GMT", 0 },
121 { "GMT+1", -1 },
122 { "GMT+2", -2 },
123 { "GMT+3", -3 },
124 { "GMT+4", -4 },
125 { "GMT+5", -5 },
126 { "GMT+6", -6 },
127 { "GMT+7", -7 },
128 { "GMT+8", -8 },
129 { "GMT+9", -9 },
130 { "GMT+10", -10 },
131 { "GMT+11", -11 },
132 { "GMT+12", -12 },
133 { "GMT-1", 1 },
134 { "GMT-2", 2 },
135 { "GMT-3", 3 },
136 { "GMT-4", 4 },
137 { "GMT-5", 5 },
138 { "GMT-6", 6 },
139 { "GMT-7", 7 },
140 { "GMT-8", 8 },
141 { "GMT-9", 9 },
142 { "GMT-10", 10 },
143 { "GMT-11", 11 },
144 { "GMT-12", 12 },
145 { "GMT-13", 13 },
146 { "GMT-14", 14 },
147 { "GMT-15", 15 },
148 { "CET", -1 },
149 { "CST", -6 },
150 { "MST", -7 },
151 { "PST", -8 },
152 { NULL, 0 }
153};
154
155
156xs_list *xs_tz_list(void)
157/* returns the list of supported timezones */
158{
159 xs_list *l = xs_list_new();
160
161 for (int n = 0; xs_tz[n].tz != NULL; n++)
162 l = xs_list_append(l, xs_tz[n].tz);
163
164 return l;
165}
166
167
168int xs_tz_offset(const char *tz)
169/* returns the offset in seconds from the specified Time Zone to UTC */
170{
171 for (int n = 0; xs_tz[n].tz != NULL; n++) {
172 if (strcmp(xs_tz[n].tz, tz) == 0)
173 return xs_tz[n].h_offset * 3600;
174 }
175
176 return 0;
177}
178
179
109#endif /* XS_IMPLEMENTATION */ 180#endif /* XS_IMPLEMENTATION */
110 181
111#endif /* _XS_TIME_H */ 182#endif /* _XS_TIME_H */