[Xfce4-commits] <xfce4-weather-plugin:master> Add code to decide between night and day for the current forecast.

Harald Judt noreply at xfce.org
Mon Jul 2 12:38:07 CEST 2012


Updating branch refs/heads/master
         to a053b251698babadbe476bf401ff65128741d7cc (commit)
       from 5b6e2f5233907b0f8d3972a50efc98829a09d3da (commit)

commit a053b251698babadbe476bf401ff65128741d7cc
Author: Harald Judt <h.judt at gmx.at>
Date:   Tue Jun 26 01:17:34 2012 +0200

    Add code to decide between night and day for the current forecast.
    
    Unless we know about sunrise and sunset times, we have to
    use hardcoded values. For now, it should be doing fine in
    most cases.

 panel-plugin/weather-data.c |   15 +++++++++++++++
 panel-plugin/weather-data.h |    2 ++
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index 6faf070..c36402e 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -152,6 +152,21 @@ get_daytime_interval(struct tm *start_t, struct tm *end_t, daytime dt)
 	}
 }
 
+/*
+ * Check whether it is night or day. Until we have a way to get the
+ * exact times for sunrise and sunset, we'll have to use reasonable
+ * hardcoded values.
+ */
+gboolean
+is_night_time()
+{
+    time_t now;
+    struct tm tm_now;
+    time(&now);
+    tm_now = *localtime(&now);
+    return (tm_now.tm_hour >= 21 || tm_now.tm_hour < 5);
+}
+
 time_t
 time_calc(struct tm tm_time, gint year, gint month, gint day, gint hour, gint min, gint sec)
 {
diff --git a/panel-plugin/weather-data.h b/panel-plugin/weather-data.h
index 1853af9..798a4ec 100644
--- a/panel-plugin/weather-data.h
+++ b/panel-plugin/weather-data.h
@@ -52,6 +52,8 @@ const gchar *
 get_data (xml_time *timeslice, datas type);
 const gchar *
 get_unit (xml_time *timeslice, units unit, datas type);
+gboolean
+is_night_time();
 time_t
 time_calc(struct tm tm_time, gint year, gint mon, gint day, gint hour, gint min, gint sec);
 time_t


More information about the Xfce4-commits mailing list