[gnome-clocks/wip/exalm/oops: 1/3] world: Ensure sunset happens after sunrise



commit eb3ae4864f3b243a6af55ebf1c83b55507083005
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Feb 24 03:46:45 2020 +0500

    world: Ensure sunset happens after sunrise
    
    When a location is placed near the international day line,
    calculate_sunrise_sunset() might return sunset time earlier than sunrise.
    Really it means that sunset happens early next day, but it throws
    everything off.
    
    To prevent this, add one day to the sunset datetime if it's in the past
    compared to the sunrise.

 src/world.vala | 8 ++++++++
 1 file changed, 8 insertions(+)
---
diff --git a/src/world.vala b/src/world.vala
index 75e3d88..e4a444c 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -275,6 +275,8 @@ public class Item : Object, ContentItem {
 
         sun_rise = new DateTime.utc (y, m, d, rise_hour, rise_min, 0).to_timezone (time_zone);
         sun_set = new DateTime.utc (y, m, d, set_hour, set_min, 0).to_timezone (time_zone);
+        if (sun_set.compare (sun_rise) < 0)
+            sun_set = sun_set.add_days (1);
 
         calculate_sunrise_sunset (lat,
                                   lon,
@@ -289,6 +291,8 @@ public class Item : Object, ContentItem {
 
         civil_rise = new DateTime.utc (y, m, d, rise_hour, rise_min, 0).to_timezone (time_zone);
         civil_set = new DateTime.utc (y, m, d, set_hour, set_min, 0).to_timezone (time_zone);
+        if (civil_set.compare (civil_rise) < 0)
+            civil_set = civil_set.add_days (1);
 
         calculate_sunrise_sunset (lat,
                                   lon,
@@ -303,6 +307,8 @@ public class Item : Object, ContentItem {
 
         naut_rise = new DateTime.utc (y, m, d, rise_hour, rise_min, 0).to_timezone (time_zone);
         naut_set = new DateTime.utc (y, m, d, set_hour, set_min, 0).to_timezone (time_zone);
+        if (naut_set.compare (naut_rise) < 0)
+            naut_set = naut_set.add_days (1);
 
         calculate_sunrise_sunset (lat,
                                   lon,
@@ -317,6 +323,8 @@ public class Item : Object, ContentItem {
 
         astro_rise = new DateTime.utc (y, m, d, rise_hour, rise_min, 0).to_timezone (time_zone);
         astro_set = new DateTime.utc (y, m, d, set_hour, set_min, 0).to_timezone (time_zone);
+        if (astro_set.compare (astro_rise) < 0)
+            astro_set = astro_set.add_days (1);
     }
 
     [Signal (run = "first")]


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