init
This commit is contained in:
24
new-planet-backend/app/utils/helpers.py
Normal file
24
new-planet-backend/app/utils/helpers.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from typing import Any, Dict
|
||||
from datetime import datetime, date
|
||||
import json
|
||||
|
||||
|
||||
def format_datetime(dt: datetime) -> str:
|
||||
"""Форматирование datetime в ISO строку"""
|
||||
return dt.isoformat()
|
||||
|
||||
|
||||
def format_date(d: date) -> str:
|
||||
"""Форматирование date в ISO строку"""
|
||||
return d.isoformat()
|
||||
|
||||
|
||||
def dict_to_json(data: Dict[str, Any]) -> str:
|
||||
"""Преобразование словаря в JSON строку"""
|
||||
return json.dumps(data, ensure_ascii=False, default=str)
|
||||
|
||||
|
||||
def json_to_dict(json_str: str) -> Dict[str, Any]:
|
||||
"""Преобразование JSON строки в словарь"""
|
||||
return json.loads(json_str)
|
||||
|
||||
Reference in New Issue
Block a user