19 lines
679 B
Python
19 lines
679 B
Python
"""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)}")
|