[Bf-extensions-cvs] [e79295c6] master: sun_position: fix time calculations

Damien Picard noreply at git.blender.org
Wed Dec 4 01:42:34 CET 2019


Commit: e79295c648af386233a03da3d563c0d7083f8e47
Author: Damien Picard
Date:   Tue Dec 3 17:01:09 2019 +0100
Branches: master
https://developer.blender.org/rBACe79295c648af386233a03da3d563c0d7083f8e47

sun_position: fix time calculations

===================================================================

M	sun_position/sun_calc.py
M	sun_position/ui_sun.py

===================================================================

diff --git a/sun_position/sun_calc.py b/sun_position/sun_calc.py
index fc4caf41..6514cdee 100644
--- a/sun_position/sun_calc.py
+++ b/sun_position/sun_calc.py
@@ -138,10 +138,7 @@ def move_sun(context):
         return
 
     local_time = sun_props.time
-    if sun_props.longitude > 0.0:
-        zone = sun_props.UTC_zone * -1
-    else:
-        zone = sun_props.UTC_zone
+    zone = -sun_props.UTC_zone
     sun.use_daylight_savings = sun_props.use_daylight_savings
     if sun.use_daylight_savings:
         zone -= 1
@@ -237,6 +234,10 @@ def update_time(context):
             sun_props.day = dt.day
         if sun_props.month != dt.month:
             sun_props.month = dt.month
+    sun.year = sun_props.year
+    sun.longitude = sun_props.longitude
+    sun.latitude = sun_props.latitude
+    sun.UTC_zone = sun_props.UTC_zone
 
 
 def format_time(the_time, UTC_zone, daylight_savings, longitude):
@@ -247,17 +248,11 @@ def format_time(the_time, UTC_zone, daylight_savings, longitude):
     ss = "0" + str(sec) if sec < 10 else str(sec)
 
     zone = UTC_zone
-    if(longitude < 0):
-        zone *= -1
     if daylight_savings:
         zone += 1
     gt = int(the_time) - zone
 
-    if gt < 0:
-        gt = 24 + gt
-    elif gt > 23:
-        gt = gt - 24
-    gt = str(gt)
+    gt = str(gt % 24)
 
     return ("Local: " + hh + ":" + mm + ":" + ss,
             "UTC: " + gt + ":" + mm + ":" + ss)
@@ -471,10 +466,7 @@ def calc_solar_noon(jd, longitude, timezone, dst):
 
 
 def calc_sunrise_sunset(rise):
-    if sun.longitude > 0:
-        zone = sun.UTC_zone * -1
-    else:
-        zone = sun.UTC_zone
+    zone = -sun.UTC_zone
 
     jd = get_julian_day(sun.year, sun.month, sun.day)
     time_UTC = calc_sunrise_set_UTC(rise, jd, sun.latitude, sun.longitude)
@@ -488,10 +480,7 @@ def calc_sunrise_sunset(rise):
     if sun.use_daylight_savings:
         time_local += 60.0
         tl = time_local / 60.0
-    if tl < 0.0:
-        tl += 24.0
-    elif tl > 24.0:
-        tl -= 24.0
+    tl %= 24.0
     if rise:
         sun.sunrise.time = tl
         sun.sunrise.azimuth = sun.azimuth
diff --git a/sun_position/ui_sun.py b/sun_position/ui_sun.py
index a6c6ecf7..ab385e94 100644
--- a/sun_position/ui_sun.py
+++ b/sun_position/ui_sun.py
@@ -282,17 +282,9 @@ class SUNPOS_PT_Panel(bpy.types.Panel):
         col = flow.column(align=True)
         col.alignment = 'CENTER'
         if p.show_rise_set:
-            if (sun.sunrise.time == sun.sunset.time
-                    or sun.sunrise.elevation > -0.4
-                    or sun.sunset.elevation  > -0.4):
-                sun.rise_set_ok = False
-                tsr = "sunrise: --------"
-                tss = " sunset: --------"
-            else:
-                sun.rise_set_ok = True
-                sr = format_hms(sun.sunrise.time)
-                ss = format_hms(sun.sunset.time)
-                tsr = "Sunrise: " + sr
-                tss = " Sunset: " + ss
+            sr = format_hms(sun.sunrise.time)
+            ss = format_hms(sun.sunset.time)
+            tsr = "Sunrise: " + sr
+            tss = " Sunset: " + ss
             col.label(text=tsr, icon='LIGHT_SUN')
             col.label(text=tss, icon='SOLO_ON')



More information about the Bf-extensions-cvs mailing list