diff --git a/CHANGELOG.md b/CHANGELOG.md index 913f48a3..b113f74d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ All notable changes to this project will be documented in this file. - Implement PagerDuty Simple Install Flow, remove PD Connect - Implement dark mode +### Bug Fixes +- Fix off-by-one-month error in monthly reports, downtime columns (#539) + ## v1.20.0 - 2020-04-22 ### Improvements diff --git a/hc/api/models.py b/hc/api/models.py index 7bc49db6..6b8dddff 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -307,7 +307,7 @@ class Check(models.Model): ping.exitstatus = exitstatus ping.save() - def downtimes(self, months=2): + def downtimes(self, months): """ Calculate the number of downtimes and downtime minutes per month. Returns a list of (datetime, downtime_in_secs, number_of_outages) tuples. @@ -351,6 +351,11 @@ class Check(models.Model): return sorted(totals.values()) + def past_downtimes(self): + """ Return downtime summary for two previous months. """ + + return self.downtimes(3)[:-1] + class Ping(models.Model): id = models.BigAutoField(primary_key=True) diff --git a/hc/lib/date.py b/hc/lib/date.py index 76859c02..b4ea943e 100644 --- a/hc/lib/date.py +++ b/hc/lib/date.py @@ -1,5 +1,4 @@ from datetime import datetime as dt -from random import randint from django.utils import timezone @@ -71,7 +70,7 @@ def format_approx_duration(td): return "" -def month_boundaries(months=2): +def month_boundaries(months): result = [] now = timezone.now() diff --git a/templates/emails/summary-downtimes-html.html b/templates/emails/summary-downtimes-html.html index ae79d10c..b513d21e 100644 --- a/templates/emails/summary-downtimes-html.html +++ b/templates/emails/summary-downtimes-html.html @@ -60,7 +60,7 @@ {% endif %} - {% for boundary, seconds, count in check.downtimes %} + {% for boundary, seconds, count in check.past_downtimes %} {% if count %} {{ count }} downtime{{ count|pluralize }},