fix date validation

This commit is contained in:
Pratyush Shukla
2023-09-06 00:53:41 +05:30
parent dc9731c575
commit 35e9ac4e03
3 changed files with 13 additions and 7 deletions

View File

@@ -46,7 +46,10 @@ class CboeEuropeanIndexHistoricalData(EuropeanIndexHistoricalData):
@validator("date", pre=True, check_fields=False)
def date_validate(cls, v): # pylint: disable=E0213
"""Return datetime object from string."""
return datetime.strptime(v, "%Y-%m-%d")
try:
return datetime.strptime(v, "%Y-%m-%d %H:%M:%S")
except Exception:
return datetime.strptime(v, "%Y-%m-%d %H:%M:%S")
class CboeEuropeanIndexHistoricalFetcher(

View File

@@ -48,7 +48,10 @@ class CboeStockHistoricalData(StockHistoricalData):
@validator("date", pre=True, check_fields=False)
def date_validate(cls, v): # pylint: disable=E0213
"""Return datetime object from string."""
return datetime.strptime(v, "%Y-%m-%d")
try:
return datetime.strptime(v, "%Y-%m-%d %H:%M:%S")
except Exception:
return datetime.strptime(v, "%Y-%m-%d")
class CboeStockHistoricalFetcher(

View File

@@ -56,13 +56,13 @@ class FMPMajorIndicesHistoricalData(MajorIndicesHistoricalData):
default=None,
)
@validator("date", pre=True)
@validator("date", pre=True, check_fields=False)
def date_validate(cls, v) -> datetime: # pylint: disable=E0213
"""Return the date as a datetime object."""
# TODO: Check if this condition is necessary
# if values.get("changeOverTime", None) is not None:
# return datetime.strptime(v, "%Y-%m-%d")
return datetime.strptime(v, "%Y-%m-%d")
try:
return datetime.strptime(v, "%Y-%m-%d %H:%M:%S")
except Exception:
return datetime.strptime(v, "%Y-%m-%d")
class FMPMajorIndicesHistoricalFetcher(