[gnome-clocks/wip/exalm/oops: 3/3] world: Handle nonexistent locations



commit e283530ca99733c4f10195976eee02fe90b7416e
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Feb 24 03:51:42 2020 +0500

    world: Handle nonexistent locations
    
    Some locations, such as UTC, don't correspond to physical locations. In
    these cases, the coords will be (inf, inf) causing a crash down the line.
    
    Since day/twilight/night doesn't make sense here, just skip the
    calculations and make the sunrise and sunset dates nullable.
    
    Introduce a neutral "none" state style class for this case and use a
    light gray color.

 data/css/gnome-clocks.css |  4 ++++
 src/world.vala            | 26 ++++++++++++++++++--------
 2 files changed, 22 insertions(+), 8 deletions(-)
---
diff --git a/data/css/gnome-clocks.css b/data/css/gnome-clocks.css
index 06153d0..8338078 100644
--- a/data/css/gnome-clocks.css
+++ b/data/css/gnome-clocks.css
@@ -275,6 +275,10 @@ spinbutton.clocks-timer-label button {
     transition: 0.4s background ease-in;
 }
 
+.none .clock-time {
+  background: #f6f5f4;
+}
+
 .night .clock-time {
   background: #a0a2b7;
 }
diff --git a/src/world.vala b/src/world.vala
index 8d7f804..0da51bf 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -199,6 +199,10 @@ public class Item : Object, ContentItem {
     // CSS class for the current time of day
     public string state_class {
         get {
+            if (sun_rise == null || sun_set == null) {
+                return "none";
+            }
+
             if (date_time.compare (sun_rise) > 0 && date_time.compare (sun_set) < 0) {
                 return "day";
             }
@@ -227,14 +231,14 @@ public class Item : Object, ContentItem {
 
     // When sunrise/sunset happens, at different corrections, in locations
     // timezone for calculating the colour pill
-    private DateTime sun_rise;
-    private DateTime sun_set;
-    private DateTime civil_rise;
-    private DateTime civil_set;
-    private DateTime naut_rise;
-    private DateTime naut_set;
-    private DateTime astro_rise;
-    private DateTime astro_set;
+    private DateTime? sun_rise;
+    private DateTime? sun_set;
+    private DateTime? civil_rise;
+    private DateTime? civil_set;
+    private DateTime? naut_rise;
+    private DateTime? naut_set;
+    private DateTime? astro_rise;
+    private DateTime? astro_set;
     // When we last calculated
     private int last_calc_day = -1;
 
@@ -259,6 +263,12 @@ public class Item : Object, ContentItem {
 
         location.get_coords (out lat, out lon);
 
+        // Some locations, such as UTC, aren't actual locations and don't have
+        // proper coords
+        if (!lat.is_finite () || !lon.is_finite ()) {
+            return;
+        }
+
         var utc = date_time.to_utc ();
         utc.get_ymd (out y, out m, out d);
 


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