Skip to content

Commit 45a5a86

Browse files
committed
naming
1 parent 9203dfd commit 45a5a86

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

stac_fastapi/mongo/database_logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from stac_fastapi.mongo.config import AsyncMongoDBSettings as AsyncSearchSettings
1717
from stac_fastapi.mongo.config import MongoDBSettings as SyncSearchSettings
1818
from stac_fastapi.mongo.utilities import (
19-
convert_datetime,
19+
convert_obj_datetimes,
2020
decode_token,
2121
encode_token,
2222
parse_datestring,
@@ -654,7 +654,7 @@ async def create_item(self, item: Item, refresh: bool = False):
654654

655655
new_item = item.copy()
656656
new_item["_id"] = item.get("_id", ObjectId())
657-
convert_datetime(new_item)
657+
convert_obj_datetimes(new_item)
658658

659659
existing_item = await items_collection.find_one({"_id": new_item["_id"]})
660660
if existing_item:

stac_fastapi/mongo/utilities.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ def parse_datestring(str):
4545
return parsed_value.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
4646

4747

48-
def convert_datetime(obj):
49-
"""
50-
Recursively converts date strings in ISO 8601 format with timezone offsets into \
51-
date strings with 'Z' timezone indicator. The input can be either a dictionary or a list, \
52-
possibly nested, containing date strings.
48+
def convert_obj_datetimes(obj):
49+
"""Recursively explores dictionaries and lists, attempting to parse strings as datestrings \
50+
into a specific format.
5351
5452
Args:
5553
obj (dict or list): The dictionary or list containing date strings to convert.
@@ -60,7 +58,7 @@ def convert_datetime(obj):
6058
if isinstance(obj, dict):
6159
for key, value in obj.items():
6260
if isinstance(value, dict) or isinstance(value, list):
63-
obj[key] = convert_datetime(value)
61+
obj[key] = convert_obj_datetimes(value)
6462
elif isinstance(value, str):
6563
try:
6664
obj[key] = parse_datestring(value)
@@ -76,5 +74,5 @@ def convert_datetime(obj):
7674
except ValueError:
7775
pass # If parsing fails, retain the original value
7876
elif isinstance(value, list):
79-
obj[i] = convert_datetime(value) # Recursively handle nested lists
77+
obj[i] = convert_obj_datetimes(value) # Recursively handle nested lists
8078
return obj

0 commit comments

Comments
 (0)