(20241226) Kafka certs in order.

This commit is contained in:
2024-12-27 18:36:16 +05:30
parent 6f2285c536
commit 61777d7f05
3 changed files with 67 additions and 20 deletions
+47
View File
@@ -146,6 +146,53 @@ class AsyncNSEBase:
def debug_everything(self):
self._debug_only_errors = False
# ┓┏ ┓
# ┣┫┏┓┃┏┓┏┓┏┓┏
# ┛┗┗ ┗┣┛┗ ┛ ┛
# ┛
@staticmethod
def parse_datetime_string(
dt_str: str,
dt_formats: str | List[str] = None,
input_tz: str = date_time.TIMEZONE_IST,
output_tz: str = date_time.TIMEZONE_UTC
) -> datetime.datetime | None:
"""
Handles the date-time conversion and normalization for strings received from NSE.
:param dt_str: The string value as received from NSE.
:param dt_formats: The format(s) in which to attempt to parse the date string.
:param input_tz: The timezone in which the input must be assumed to be.
:param output_tz: The timezone the output must be converted to.
:return: The parsed datetime object, or null if parsing fails.
"""
# Basic input formatting:
dt_formats = dt_formats or "%d-%b-%Y"
# Try to parse the date-time string:
if isinstance(dt_formats, list):
dt_obj = date_time.parse_date_time(
input_value = dt_str,
date_formats = dt_formats
)
else:
try: dt_obj = datetime.datetime.strptime(dt_str, dt_formats)
except: dt_obj = None
# If the parsing failed:
if not dt_obj: return None
# If parsed successfully:
return date_time.to_timezone(
datetime_object = date_time.as_if_timezone(
datetime_object = dt_obj,
timezone = input_tz
),
timezone = output_tz
)
# ┏┓ ┓ • ┳┳┓ ┓ •
# ┃ ┏┓┏┓┃┏┓┏┓┏ ┃┃┃┏┓┃┏┓┏┓┏┓
# ┗┛┗┛┗┛┛┗┗┗ ┛ ┛ ┗┗┻┛┗┗┛┗┗┫