From a0459bd95a8a3d7854440734efd8304b94d1b0a4 Mon Sep 17 00:00:00 2001 From: CamelBackNotation Date: Fri, 6 Mar 2015 15:55:24 -0600 Subject: [PATCH] Added macro function to fix the issue where -0F was being displayed to the user. --- panel-plugin/weather-data.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c index 3728199..7d00eff 100644 --- a/panel-plugin/weather-data.c +++ b/panel-plugin/weather-data.c @@ -44,6 +44,13 @@ #define ROUND_TO_INT(default_format) (round ? "%.0f" : default_format) +/* Converts Celcius to Fahrenheit while preventing -0F from being displayed to user. + * Used in function get_data for TEMPERATURE, DEWPOINT, APPARENT_TEMPERATURE. */ +#define CALC_FAHRENHEIT(round, temperature) \ + temperature = temperature * 9.0 / 5.0 + 32; \ + if (round && temperature > -0.5 && temperature < 0) \ + temperature = 0; \ + #define LOCALE_DOUBLE(value, format) \ (value \ ? g_strdup_printf(format, g_ascii_strtod(value, NULL)) \ @@ -344,8 +351,8 @@ get_data(const xml_time *timeslice, case TEMPERATURE: /* source is in °C */ val = string_to_double(loc->temperature_value, 0); if (units->temperature == FAHRENHEIT) - val = val * 9.0 / 5.0 + 32.0; - return g_strdup_printf(ROUND_TO_INT("%.1f"), val); + CALC_FAHRENHEIT(round, val); + return g_strdup_printf(ROUND_TO_INT("%.1f"), val); case PRESSURE: /* source is in hectopascals */ val = string_to_double(loc->pressure_value, 0); @@ -398,14 +405,14 @@ get_data(const xml_time *timeslice, if (val == INVALID_VALUE) return g_strdup(""); if (units->temperature == FAHRENHEIT) - val = val * 9.0 / 5.0 + 32.0; + CALC_FAHRENHEIT(round, val); return g_strdup_printf(ROUND_TO_INT("%.1f"), val); case APPARENT_TEMPERATURE: val = calc_apparent_temperature(loc, units->apparent_temperature, night_time); if (units->temperature == FAHRENHEIT) - val = val * 9.0 / 5.0 + 32.0; + CALC_FAHRENHEIT(round, val); return g_strdup_printf(ROUND_TO_INT("%.1f"), val); case CLOUDS_LOW: -- 2.1.0