mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 14:02:06 +00:00
fix date validation
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user