From 153c74efa8c71af2e3e696c4e2d6492a6fe23bb7 Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Sat, 9 Aug 2025 14:12:00 -0700 Subject: [PATCH] Fix problem with delta times. Fixes issue #1009. --- docs_src/changes.md | 3 +++ src/weewx/almanac.py | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs_src/changes.md b/docs_src/changes.md index 618c2832..47a1020b 100644 --- a/docs_src/changes.md +++ b/docs_src/changes.md @@ -28,6 +28,9 @@ The utility and documentation have been changed to use `cur_in_temp` (one '`r`'), making all types consistent. Fixes [Issue #1006](https://github.com/weewx/weewx/issues/1006). +Fix a problem caused by an assumption that delta times are always in seconds. +Fixes issue [Issue #1009](https://github.com/weewx/weewx/issues/1009). + ### 5.1.0 07/04/2024 diff --git a/src/weewx/almanac.py b/src/weewx/almanac.py index 398d3a96..b538e69c 100644 --- a/src/weewx/almanac.py +++ b/src/weewx/almanac.py @@ -415,17 +415,17 @@ class AlmanacBinder: def visible_change(self, days_ago=1): """Change in visibility of the heavenly body compared to 'days_ago'.""" - # Visibility for today: + # Visibility for today, as a ValueTuple today_visible = self.visible # The time to compare to then_time = self.almanac.time_ts - days_ago * 86400 # Get a new almanac, set up for the time back then then_almanac = self.almanac(almanac_time=then_time) - # Find the visibility back then + # Find the visibility back then as a ValueTuple then_visible = getattr(then_almanac, self.heavenly_body).visible - # Take the difference - diff = today_visible.raw - then_visible.raw - return weewx.units.ValueHelper(ValueTuple(diff, "second", "group_deltatime"), + # Take the difference, which will also be a ValueTuple + diff_vt = today_visible.value_t - then_visible.value_t + return weewx.units.ValueHelper(diff_vt, context="hour", formatter=self.almanac.formatter, converter=self.almanac.converter)