[gnome-weather/gnome-3-8] TodaySidebar: Fix showing forecast for tomorrow



commit a63ccf103eb405b17b9708e062709fdf7e655f97
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue Mar 5 23:45:20 2013 +0100

    TodaySidebar: Fix showing forecast for tomorrow
    
    The trimming loop was bailing out to early if the decided to show
    forecast for tomorrow but we had one info for today.

 src/forecast.js |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/src/forecast.js b/src/forecast.js
index 0b966a4..0cb0f78 100644
--- a/src/forecast.js
+++ b/src/forecast.js
@@ -174,9 +174,28 @@ const TodaySidebar = new Lang.Class({
     // remove infos for the wrong day
     _preprocess: function(now, infos) {
         let ret = [];
-        let current = now;
+        let i;
+        let current;
+
+        // First ignore all infos that are on a different
+        // day than now.
+        // infos are ordered by time, and it's assumed at some point
+        // there is an info for the current day (otherwise, nothing
+        // is shown)
+        for (i = 0; i < infos.length; i++) {
+            let info = infos[i];
+
+            let [ok, date] = info.get_value_update();
+            let datetime = GLib.DateTime.new_from_unix_local(date);
+
+            if (Util.arrayEqual(now.get_ymd(),
+                                datetime.get_ymd())) {
+                current = datetime;
+                break;
+            }
+        }
 
-        for (let i = 0; i < infos.length; i++) {
+        for ( ; i < infos.length; i++) {
             let info = infos[i];
 
             let [ok, date] = info.get_value_update();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]