From e52d86b364fd44cc2f4f6f0b0ecc65c18888ef10 Mon Sep 17 00:00:00 2001 From: Kristian Krsnik Date: Thu, 5 Oct 2023 12:16:05 +0200 Subject: [PATCH] Fixed a bug, added documentation and type annotations --- outage_detector/main.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/outage_detector/main.py b/outage_detector/main.py index a6bfd44..5d5806a 100644 --- a/outage_detector/main.py +++ b/outage_detector/main.py @@ -1,6 +1,6 @@ import sys import argparse -from datetime import datetime +from datetime import datetime, timedelta import requests @@ -27,18 +27,27 @@ class Outage: Could be None to represent that the outage is still ongoing. ''' - def __init__(self, start: LogEntry, end: None | LogEntry = None): + def __init__(self, start: LogEntry, end: None | LogEntry = None) -> None: + ''' + Initialize an outage. + + `start` The start of an outage represented by a LogEntry object. + + `end` The end of an outage represented by a LogEntry object. + By default it is none to represent an ongoing outage. + ''' + self.start = start self.end = end - def duration(self) -> datetime: + def duration(self) -> timedelta: ''' Return the duration of the outage as datetime object. If the outage does not have an end, the time from the start to now will be returned. ''' if self.end is None: - return self.end.date - datetime.now() + return datetime.now() - self.start.date else: return self.end.date - self.start.date