From 35e9ac4e033e6435c9e71a6c67a6fb759f7d8009 Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Wed, 6 Sep 2023 00:53:41 +0530 Subject: [PATCH] fix `date` validation --- .../openbb_cboe/models/european_index_historical.py | 5 ++++- .../cboe/openbb_cboe/models/stock_historical.py | 5 ++++- .../fmp/openbb_fmp/models/major_indices_historical.py | 10 +++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/openbb_sdk/providers/cboe/openbb_cboe/models/european_index_historical.py b/openbb_sdk/providers/cboe/openbb_cboe/models/european_index_historical.py index ea41ba78843..b5f35b81c92 100644 --- a/openbb_sdk/providers/cboe/openbb_cboe/models/european_index_historical.py +++ b/openbb_sdk/providers/cboe/openbb_cboe/models/european_index_historical.py @@ -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( diff --git a/openbb_sdk/providers/cboe/openbb_cboe/models/stock_historical.py b/openbb_sdk/providers/cboe/openbb_cboe/models/stock_historical.py index 54c5d722c7f..50a56b6741e 100644 --- a/openbb_sdk/providers/cboe/openbb_cboe/models/stock_historical.py +++ b/openbb_sdk/providers/cboe/openbb_cboe/models/stock_historical.py @@ -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( diff --git a/openbb_sdk/providers/fmp/openbb_fmp/models/major_indices_historical.py b/openbb_sdk/providers/fmp/openbb_fmp/models/major_indices_historical.py index d367f166c8a..6f401a3cbee 100644 --- a/openbb_sdk/providers/fmp/openbb_fmp/models/major_indices_historical.py +++ b/openbb_sdk/providers/fmp/openbb_fmp/models/major_indices_historical.py @@ -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(