summaryrefslogtreecommitdiff
path: root/input_gadgets.c
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-11-23 11:55:56 +0100
committerErich Eckner <git@eckner.net>2018-11-23 11:56:06 +0100
commitc8125d4db2e51430ef0d78e708ee91ac704520f7 (patch)
tree4bd2bea872e7b9c5d477c7520319ab953bb88df0 /input_gadgets.c
parent0a0cea338f1639d732121349f241ba52732021ca (diff)
downloadanzeige-c8125d4db2e51430ef0d78e708ee91ac704520f7.tar.xz
input_gadgets.c: Zeitformat angepasst: Tag weglassen, wenn heute
Diffstat (limited to 'input_gadgets.c')
-rw-r--r--input_gadgets.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/input_gadgets.c b/input_gadgets.c
index b1d2619..02e1e98 100644
--- a/input_gadgets.c
+++ b/input_gadgets.c
@@ -121,6 +121,23 @@ int point_is_inside_polygon(double lat, double lon, char *text)
return is_inside;
}
+size_t adaptive_strftime(char *s, size_t max, const struct tm *tm_print)
+{
+ if (max<=0)
+ return 0;
+ time_t now = time(NULL);
+ struct tm tm_now;
+ memset(&tm_now, 0, sizeof(tm_now));
+ localtime_r(&now, &tm_now);
+ if (tm_now . tm_year != tm_print -> tm_year)
+ return strftime(s, max, "%Y-%m-%d %H:%M", tm_print);
+ if (tm_now . tm_mon != tm_print -> tm_mon)
+ return strftime(s, max, "%m-%d %H:%M", tm_print);
+ if (tm_now . tm_mday != tm_print -> tm_mday)
+ return strftime(s, max, "%d. %H:%M", tm_print);
+ return strftime(s, max, "%H:%M", tm_print);
+}
+
char *gadgets_retrieve_current_temperature(char *output, int max_len)
{
CURL *curl_handle;
@@ -191,7 +208,11 @@ char *gadgets_retrieve_current_temperature(char *output, int max_len)
for (char *i = output; i < ende; i++)
if (*i == '.')
*i = ',';
- ende += strftime(ende, output + max_len - ende, " (%m-%d %H:%M)", &time_struct);
+ if (output + max_len - ende > 0)
+ ende += snprintf(ende, output + max_len - ende, " (");
+ ende += adaptive_strftime(ende, output + max_len - ende, &time_struct);
+ if (output + max_len - ende > 0)
+ ende += snprintf(ende, output + max_len - ende, ")");
}
free(chunk.memory);
return ende;
@@ -906,12 +927,18 @@ char *gadgets_retrieve_weather_warnings(char *output, int max_len)
if (output + max_len - ende > 0) {
ende += snprintf(ende, output + max_len - ende, "%s", warnings[i].event);
if (output + max_len - ende > 0) {
- if (warnings[i].onset > time(NULL))
- ende += strftime(ende, output + max_len - ende, " ab %m-%d %H:%M", localtime(&warnings[i].onset));
- if (warnings[i].expires < time(NULL) + warnings_future_timespan)
- ende += strftime(ende, output + max_len - ende, " bis %m-%d %H:%M", localtime(&warnings[i].expires));
+ if (warnings[i].onset > time(NULL)) {
+ if (output + max_len - ende > 0)
+ ende += snprintf(ende, output + max_len - ende, " ab ");
+ ende += adaptive_strftime(ende, output + max_len - ende, localtime(&warnings[i].onset));
+ }
+ if (warnings[i].expires < time(NULL) + warnings_future_timespan) {
+ if (output + max_len - ende > 0)
+ ende += snprintf(ende, output + max_len - ende, " bis");
+ ende += adaptive_strftime(ende, output + max_len - ende, localtime(&warnings[i].expires));
+ }
if ((i+1<warnings_len) && (output + max_len - ende > 0))
- ende += snprintf(ende, output + max_len - ende, "; ", warnings[i].event);
+ ende += snprintf(ende, output + max_len - ende, "; ");
}
}