update db str
This commit is contained in:
18
backend/utils.py
Normal file
18
backend/utils.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""Utility functions"""
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
|
||||
def utc_to_ist(utc_datetime: datetime) -> datetime:
|
||||
"""Convert UTC datetime to IST (Indian Standard Time)"""
|
||||
ist_offset = timezone(timedelta(hours=5, minutes=30))
|
||||
return utc_datetime.replace(tzinfo=timezone.utc).astimezone(ist_offset)
|
||||
|
||||
|
||||
def format_ist_timestamp(utc_iso_string: str) -> str:
|
||||
"""Convert UTC ISO string to IST ISO string"""
|
||||
try:
|
||||
utc_dt = datetime.fromisoformat(utc_iso_string.replace('Z', '+00:00'))
|
||||
ist_dt = utc_to_ist(utc_dt)
|
||||
return ist_dt.isoformat()
|
||||
except Exception as e:
|
||||
raise ValueError(f"Invalid datetime format: {str(e)}")
|
||||
Reference in New Issue
Block a user