[Bf-extensions-cvs] [e8696b04] master: sun_position: UTC zone as float

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


Commit: e8696b04ee43151c51e68c0503a7cf850e9fee58
Author: Damien Picard
Date:   Wed Dec 4 01:08:09 2019 +0100
Branches: master
https://developer.blender.org/rBACe8696b04ee43151c51e68c0503a7cf850e9fee58

sun_position: UTC zone as float

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

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

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

diff --git a/sun_position/properties.py b/sun_position/properties.py
index 347ab016..5fbf1540 100644
--- a/sun_position/properties.py
+++ b/sun_position/properties.py
@@ -113,10 +113,11 @@ class SunPosProperties(PropertyGroup):
         min=1, max=366, default=1,
         update=sun_update)
 
-    UTC_zone: IntProperty(
+    UTC_zone: FloatProperty(
         name="UTC zone",
         description="Time zone: Difference from Greenwich, England in hours",
-        min=-12, max=12, default=0,
+        precision=1,
+        min=-14.0, max=13, step=50, default=0.0,
         update=sun_update)
 
     time: FloatProperty(
diff --git a/sun_position/sun_calc.py b/sun_position/sun_calc.py
index 6514cdee..e23abb66 100644
--- a/sun_position/sun_calc.py
+++ b/sun_position/sun_calc.py
@@ -240,22 +240,19 @@ def update_time(context):
     sun.UTC_zone = sun_props.UTC_zone
 
 
-def format_time(the_time, UTC_zone, daylight_savings, longitude):
-    hh = str(int(the_time))
-    min = (the_time - int(the_time)) * 60
-    sec = int((min - int(min)) * 60)
-    mm = "0" + str(int(min)) if min < 10 else str(int(min))
-    ss = "0" + str(sec) if sec < 10 else str(sec)
+def format_time(the_time, daylight_savings, longitude, UTC_zone=None):
+    if UTC_zone is not None:
+        if daylight_savings:
+            UTC_zone += 1
+        the_time -= UTC_zone
 
-    zone = UTC_zone
-    if daylight_savings:
-        zone += 1
-    gt = int(the_time) - zone
+    the_time %= 24
 
-    gt = str(gt % 24)
+    hh = int(the_time)
+    mm = (the_time - int(the_time)) * 60
+    ss = int((mm - int(mm)) * 60)
 
-    return ("Local: " + hh + ":" + mm + ":" + ss,
-            "UTC: " + gt + ":" + mm + ":" + ss)
+    return ("%02i:%02i:%02i" % (hh, mm, ss))
 
 
 def format_hms(the_time):
diff --git a/sun_position/ui_sun.py b/sun_position/ui_sun.py
index ab385e94..dc809c8e 100644
--- a/sun_position/ui_sun.py
+++ b/sun_position/ui_sun.py
@@ -263,20 +263,23 @@ class SUNPOS_PT_Panel(bpy.types.Panel):
         col.separator()
 
         col = flow.column(align=True)
-        lt, ut = format_time(sp.time,
-                             sp.UTC_zone,
-                             p.show_daylight_savings and sp.use_daylight_savings,
-                             sp.longitude)
         col.prop(sp, "time")
         col.prop(sp, "UTC_zone")
         if p.show_daylight_savings:
             col.prop(sp, "use_daylight_savings", text="Daylight Savings")
         col.separator()
 
+        lt = format_time(sp.time,
+                         p.show_daylight_savings and sp.use_daylight_savings,
+                         sp.longitude)
+        ut = format_time(sp.time,
+                         p.show_daylight_savings and sp.use_daylight_savings,
+                         sp.longitude,
+                         sp.UTC_zone)
         col = flow.column(align=True)
         col.alignment = 'CENTER'
-        col.label(text=lt, icon='TIME')
-        col.label(text="  " + ut, icon='PREVIEW_RANGE')
+        col.label(text="Local: " + lt, icon='TIME')
+        col.label(text="  UTC: " + ut, icon='PREVIEW_RANGE')
         col.separator()
 
         col = flow.column(align=True)



More information about the Bf-extensions-cvs mailing list