Fixed a bug, added documentation and type annotations

This commit is contained in:
Kristian Krsnik 2023-10-05 12:16:05 +02:00
parent a5be7878ff
commit e52d86b364
Signed by: Kristian
GPG Key ID: FD1330AC9F909E85

View File

@ -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