[Xfce4-commits] [panel-plugins/xfce4-weather-plugin] 04/05: Fix processing day of astrodata.
noreply at xfce.org
noreply at xfce.org
Thu Oct 23 13:19:28 CEST 2014
This is an automated email from the git hooks/post-receive script.
hjudt pushed a commit to branch master
in repository panel-plugins/xfce4-weather-plugin.
commit b8162546a0cee1b99effcf66b4ac4effb139d5ab
Author: Harald Judt <h.judt at gmx.at>
Date: Wed Oct 22 21:13:31 2014 +0200
Fix processing day of astrodata.
The way the day information of astrodata is processed is erroneous
and leads to different problems regarding localtime and timezones.
This commit fixes this by extending parse_timestring to generate
either local or gmt times and make the other parts use this for
parsing astrodata instead of applying clumsy, non-functional
workarounds.
---
panel-plugin/weather-parsers.c | 24 ++++++++++++++----------
panel-plugin/weather-parsers.h | 3 ++-
panel-plugin/weather.c | 25 ++++++++++++-------------
3 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index ed42dbe..acd7cf9 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -121,7 +121,8 @@ get_astro(const GArray *astrodata,
time_t
parse_timestring(const gchar *ts,
- gchar *format) {
+ gchar *format,
+ gboolean local) {
time_t t;
struct tm tm;
@@ -141,7 +142,11 @@ parse_timestring(const gchar *ts,
if (G_UNLIKELY(strptime(ts, format, &tm) == NULL))
return t;
- t = my_timegm(&tm);
+ if (local)
+ t = mktime(&tm);
+ else
+ t = my_timegm(&tm);
+
return t;
}
@@ -293,11 +298,11 @@ parse_time(xmlNode *cur_node,
xmlFree(datatype);
from = PROP(cur_node, "from");
- start_t = parse_timestring(from, NULL);
+ start_t = parse_timestring(from, NULL, FALSE);
xmlFree(from);
to = PROP(cur_node, "to");
- end_t = parse_timestring(to, NULL);
+ end_t = parse_timestring(to, NULL, FALSE);
xmlFree(to);
if (G_UNLIKELY(!start_t || !end_t))
@@ -388,11 +393,11 @@ parse_astro_location(xmlNode *cur_node,
xmlFree(never_sets);
sunrise = PROP(child_node, "rise");
- astro->sunrise = parse_timestring(sunrise, NULL);
+ astro->sunrise = parse_timestring(sunrise, NULL, FALSE);
xmlFree(sunrise);
sunset = PROP(child_node, "set");
- astro->sunset = parse_timestring(sunset, NULL);
+ astro->sunset = parse_timestring(sunset, NULL, FALSE);
xmlFree(sunset);
}
@@ -416,11 +421,11 @@ parse_astro_location(xmlNode *cur_node,
xmlFree(never_sets);
moonrise = PROP(child_node, "rise");
- astro->moonrise = parse_timestring(moonrise, NULL);
+ astro->moonrise = parse_timestring(moonrise, NULL, FALSE);
xmlFree(moonrise);
moonset = PROP(child_node, "set");
- astro->moonset = parse_timestring(moonset, NULL);
+ astro->moonset = parse_timestring(moonset, NULL, FALSE);
xmlFree(moonset);
astro->moon_phase = PROP(child_node, "phase");
@@ -441,8 +446,7 @@ parse_astro_time(xmlNode *cur_node)
return NULL;
date = PROP(cur_node, "date");
- astro->day = parse_timestring(date, "%Y-%m-%d");
- astro->day = day_at_midnight(astro->day, 0);
+ astro->day = parse_timestring(date, "%Y-%m-%d", TRUE);
xmlFree(date);
for (child_node = cur_node->children; child_node;
diff --git a/panel-plugin/weather-parsers.h b/panel-plugin/weather-parsers.h
index 383ad2f..71e3f4d 100644
--- a/panel-plugin/weather-parsers.h
+++ b/panel-plugin/weather-parsers.h
@@ -125,7 +125,8 @@ xml_weather *make_weather_data(void);
xml_time *make_timeslice(void);
time_t parse_timestring(const gchar *ts,
- gchar *format);
+ gchar *format,
+ gboolean local);
gboolean parse_weather(xmlNode *cur_node,
xml_weather *wd);
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 63214c4..79e7ef4 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -1095,7 +1095,7 @@ write_cache_file(plugin_data *data)
astro = g_array_index(data->astrodata, xml_astro *, i);
if (G_UNLIKELY(astro == NULL))
continue;
- value = format_date(astro->day, date_format, TRUE);
+ value = format_date(astro->day, "%Y-%m-%d", TRUE);
start = format_date(astro->sunrise, date_format, FALSE);
end = format_date(astro->sunset, date_format, FALSE);
g_string_append_printf(out, "[astrodata%d]\n", i);
@@ -1243,7 +1243,7 @@ read_cache_file(plugin_data *data)
}
/* read cache creation date and check if cache file is not too old */
CACHE_READ_STRING(timestring, "cache_date");
- cache_date_t = parse_timestring(timestring, NULL);
+ cache_date_t = parse_timestring(timestring, NULL, FALSE);
g_free(timestring);
if (difftime(now_t, cache_date_t) > data->cache_file_max_age) {
weather_debug("Cache file is too old and will not be used.");
@@ -1252,7 +1252,7 @@ read_cache_file(plugin_data *data)
}
if (G_LIKELY(data->weather_update)) {
CACHE_READ_STRING(timestring, "last_weather_download");
- data->weather_update->last = parse_timestring(timestring, NULL);
+ data->weather_update->last = parse_timestring(timestring, NULL, FALSE);
data->weather_update->next =
calc_next_download_time(data->weather_update,
data->weather_update->last);
@@ -1260,7 +1260,7 @@ read_cache_file(plugin_data *data)
}
if (G_LIKELY(data->astro_update)) {
CACHE_READ_STRING(timestring, "last_astro_download");
- data->astro_update->last = parse_timestring(timestring, NULL);
+ data->astro_update->last = parse_timestring(timestring, NULL, FALSE);
data->astro_update->next =
calc_next_download_time(data->astro_update,
data->astro_update->last);
@@ -1279,14 +1279,13 @@ read_cache_file(plugin_data *data)
break;
CACHE_READ_STRING(timestring, "day");
- astro->day = parse_timestring(timestring, NULL);
- astro->day = day_at_midnight(astro->day, 0);
+ astro->day = parse_timestring(timestring, "%Y-%m-%d", TRUE);
g_free(timestring);
CACHE_READ_STRING(timestring, "sunrise");
- astro->sunrise = parse_timestring(timestring, NULL);
+ astro->sunrise = parse_timestring(timestring, NULL, FALSE);
g_free(timestring);
CACHE_READ_STRING(timestring, "sunset");
- astro->sunset = parse_timestring(timestring, NULL);
+ astro->sunset = parse_timestring(timestring, NULL, FALSE);
g_free(timestring);
astro->sun_never_rises =
g_key_file_get_boolean(keyfile, group, "sun_never_rises", NULL);
@@ -1294,10 +1293,10 @@ read_cache_file(plugin_data *data)
g_key_file_get_boolean(keyfile, group, "sun_never_sets", NULL);
CACHE_READ_STRING(timestring, "moonrise");
- astro->moonrise = parse_timestring(timestring, NULL);
+ astro->moonrise = parse_timestring(timestring, NULL, FALSE);
g_free(timestring);
CACHE_READ_STRING(timestring, "moonset");
- astro->moonset = parse_timestring(timestring, NULL);
+ astro->moonset = parse_timestring(timestring, NULL, FALSE);
g_free(timestring);
CACHE_READ_STRING(astro->moon_phase, "moon_phase");
astro->moon_never_rises =
@@ -1331,13 +1330,13 @@ read_cache_file(plugin_data *data)
/* parse time strings (start, end, point) */
CACHE_READ_STRING(timestring, "start");
- timeslice->start = parse_timestring(timestring, NULL);
+ timeslice->start = parse_timestring(timestring, NULL, FALSE);
g_free(timestring);
CACHE_READ_STRING(timestring, "end");
- timeslice->end = parse_timestring(timestring, NULL);
+ timeslice->end = parse_timestring(timestring, NULL, FALSE);
g_free(timestring);
CACHE_READ_STRING(timestring, "point");
- timeslice->point = parse_timestring(timestring, NULL);
+ timeslice->point = parse_timestring(timestring, NULL, FALSE);
g_free(timestring);
/* parse location data */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list