Add properties to simplify timerange handling

This commit is contained in:
Matthias
2022-11-10 16:33:57 +01:00
parent 88ad3fe43e
commit 3e676dbaa4
2 changed files with 18 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ This module contains the argument manager class
"""
import logging
import re
from datetime import datetime
from datetime import datetime, timezone
from typing import Optional
import arrow
@@ -29,6 +29,16 @@ class TimeRange:
self.startts: int = startts
self.stopts: int = stopts
@property
def startdt(self) -> Optional[datetime]:
if self.startts:
return datetime.fromtimestamp(self.startts, tz=timezone.utc)
@property
def stopdt(self) -> Optional[datetime]:
if self.stopts:
return datetime.fromtimestamp(self.stopts, tz=timezone.utc)
def __eq__(self, other):
"""Override the default Equals behavior"""
return (self.starttype == other.starttype and self.stoptype == other.stoptype