diff --git a/app/api/endpoints/endpoint.py b/app/api/endpoints/endpoint.py index e69de29..ece9251 100644 --- a/app/api/endpoints/endpoint.py +++ b/app/api/endpoints/endpoint.py @@ -0,0 +1,25 @@ +from typing import Optional +from fastapi import APIRouter, Depends, HTTPException +from pydantic import BaseModel +from datetime import datetime, timezone + +router = APIRouter() + +class TimezoneRequest(BaseModel): + timezone: str + +class TimezoneResponse(BaseModel): + current_time: str + +@router.post("/timezone", response_model=TimezoneResponse) +async def get_current_time(request: TimezoneRequest): + """ + Get the current time for a given timezone + """ + try: + tz = timezone(request.timezone) + except ValueError as e: + raise HTTPException(status_code=400, detail=str(e)) + + current_time = datetime.now(tz).isoformat() + return {"current_time": current_time} \ No newline at end of file