From c9bfa485f5e7b6b1e536a0200af0bee6e0b18b74 Mon Sep 17 00:00:00 2001 From: gouravkr Date: Sat, 26 Feb 2022 20:41:21 +0530 Subject: [PATCH] Added DateOutOfRangeError --- fincal/exceptions.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fincal/exceptions.py b/fincal/exceptions.py index 2561952..0e5e0ab 100644 --- a/fincal/exceptions.py +++ b/fincal/exceptions.py @@ -1,6 +1,21 @@ +import datetime +from typing import Literal + + class DateNotFoundError(Exception): """Exception to be raised when date is not found""" def __init__(self, message, date): message = f"{message}: {date}" super().__init__(message) + + +class DateOutOfRangeError(Exception): + """Exception to be raised when provided date is outside the range of dates in the time series""" + + def __init__(self, date: datetime.datetime, type: Literal['min', 'max']) -> None: + if type == 'min': + message = f"Provided date {date} is before the first date in the TimeSeries" + if type == 'max': + message = f"Provided date {date} is after the last date in the TimeSeries" + super().__init__(message)